UBERF-10355 Adjust image transformation parameters to increase quality (#8705)

Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
This commit is contained in:
Alexander Onnikov 2025-04-25 15:01:07 +07:00 committed by GitHub
parent 1959b9f107
commit 17ac05f126
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -26,6 +26,33 @@ import { TemporaryDir } from '../tempdir'
const cacheControl = 'public, max-age=31536000, immutable' const cacheControl = 'public, max-age=31536000, immutable'
const prefferedImageFormats = ['webp', 'avif', 'jpeg', 'png'] const prefferedImageFormats = ['webp', 'avif', 'jpeg', 'png']
const QualityConfig = {
jpeg: {
quality: 85, // default + 5
progressive: true,
chromaSubsampling: '4:4:4'
} satisfies sharp.JpegOptions,
avif: {
quality: 60, // default + 10
effort: 5, // default + 1
chromaSubsampling: '4:4:4' // default
} satisfies sharp.AvifOptions,
webp: {
quality: 80, // default
alphaQuality: 100, // default
smartSubsample: true, // Better sharpness
effort: 5 // default + 1
} satisfies sharp.WebpOptions,
heif: {
quality: 80, // default + 30
effort: 5 // default + 1
} satisfies sharp.HeifOptions,
png: {
quality: 100, // default
effort: 7 // default
} satisfies sharp.PngOptions
}
interface ImageTransform { interface ImageTransform {
format: string format: string
dpr?: number dpr?: number
@ -153,34 +180,23 @@ async function runPipeline (
let contentType = 'image/jpeg' let contentType = 'image/jpeg'
switch (format) { switch (format) {
case 'jpeg': case 'jpeg':
pipeline = pipeline.jpeg({ pipeline = pipeline.jpeg(QualityConfig.jpeg)
progressive: true
})
contentType = 'image/jpeg' contentType = 'image/jpeg'
break break
case 'avif': case 'avif':
pipeline = pipeline.avif({ pipeline = pipeline.avif(QualityConfig.avif)
lossless: false,
effort: 0
})
contentType = 'image/avif' contentType = 'image/avif'
break break
case 'heif': case 'heif':
pipeline = pipeline.heif({ pipeline = pipeline.heif(QualityConfig.heif)
effort: 0
})
contentType = 'image/heif' contentType = 'image/heif'
break break
case 'webp': case 'webp':
pipeline = pipeline.webp({ pipeline = pipeline.webp(QualityConfig.webp)
effort: 0
})
contentType = 'image/webp' contentType = 'image/webp'
break break
case 'png': case 'png':
pipeline = pipeline.png({ pipeline = pipeline.png(QualityConfig.png)
effort: 0
})
contentType = 'image/png' contentType = 'image/png'
break break
} }