Closed yunhaoww closed 3 months ago
So should I add the below check, if the there is no format operation, and the source format is svg, then change the output format to png. Can you try it?
if (operationsJSON['format']) {
var isLossy = false;
switch (operationsJSON['format']) {
case 'jpeg': contentType = 'image/jpeg'; isLossy = true; break;
case 'gif': contentType = 'image/gif'; break;
case 'webp': contentType = 'image/webp'; isLossy = true; break;
case 'png': contentType = 'image/png'; break;
case 'avif': contentType = 'image/avif'; isLossy = true; break;
default: contentType = 'image/jpeg'; isLossy = true;
}
if (operationsJSON['quality'] && isLossy) {
transformedImage = transformedImage.toFormat(operationsJSON['format'], {
quality: parseInt(operationsJSON['quality']),
});
} else transformedImage = transformedImage.toFormat(operationsJSON['format']);
} else {
if (contentType = 'image/svg+xml') contentType = 'image/png';
}
@achrafsouk Thank you achrafsouk. Already used in my work; works ok
thank you, will update the code
when we request svg image directly
what will be executed with sharp are:
content-type keep as "image/svg+xml" which differs from the docs
which result a wrong image render from browser