cms
cms copied to clipboard
[4.4.15]: Quality setting does not work for transforms of png images
What happened?
Description
Transforms of png images to any format always result in the same file size, irrespective of the quality setting.
The file size is large, so I assume the output quality is always maximum.
This happens both on local (latest DDEV) and on a server provisioned with Ploi with all the latest updates.
ImageMagick version from system report: Imagick 3.7.0 (ImageMagick 6.9.11-60)
Steps to reproduce
- Upload a png image file to any asset folder.
- Output a transform of this asset in a template, either with a named transform or with a template defined transform, with a quality of 100.
- Take note of the file size.
- Change the transform quality setting to a lower quality.
- Check the new file size.
Expected behavior
The file size should be lower, due to lower quality
Actual behavior
The file size remains exactly the same, no matter how low the quality setting.
Craft CMS version
4.4.15
PHP version
8.2.8
Operating system and version
No response
Database type and version
No response
Image driver and version
Imagick 3.7.0 (ImageMagick 6.9.11-60)
Installed plugins and versions
I’m able to reproduce this, but I don’t believe it’s a bug.
PNG images don’t technically have a quality; they have a compression level. I verified that different quality values will result in different values(*) getting passed to Imagick::setImageCompressionQuality()
, but I don’t know enough about the inner workings of ImageMagick to know why that would still result in the same filesize (at least for some PNGs).
*worth noting that PNG compression levels get normalized to an integer between 0 and 9. E.g. a quality of 82 will end up with a compression level of 2
. So subtle changes in quality will definitely have no effect.
Even so, when the transform is converting the image to another file type such as webp
, the quality setting should have an effect! In this case it doesn't. Also, I think I tried at somepoint to transform from png
with transparency to jpeg
and the resulting image retained the transparency. It almost seems like the images are not converted but kept as png
and only the file extension changes.
Also FWIW, I'm not talking about subtle changes. Even going from 100 to 10 quality has no effect.
Looks like you might be right. Looking into it…
Fixed transform format swapping for the next release, however that’s unrelated to PNG image compression, which is still not seeming to have any effect.
Craft 4.4.17 is out with a fix for format
swapping.