cms icon indicating copy to clipboard operation
cms copied to clipboard

[4.4.15]: Quality setting does not work for transforms of png images

Open thupsi opened this issue 1 year ago • 6 comments

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

  1. Upload a png image file to any asset folder.
  2. 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.
  3. Take note of the file size.
  4. Change the transform quality setting to a lower quality.
  5. 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

thupsi avatar Aug 01 '23 19:08 thupsi

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.

brandonkelly avatar Aug 03 '23 18:08 brandonkelly

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.

thupsi avatar Aug 03 '23 18:08 thupsi

Also FWIW, I'm not talking about subtle changes. Even going from 100 to 10 quality has no effect.

thupsi avatar Aug 03 '23 18:08 thupsi

Looks like you might be right. Looking into it…

brandonkelly avatar Aug 04 '23 00:08 brandonkelly

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.

brandonkelly avatar Aug 04 '23 01:08 brandonkelly

Craft 4.4.17 is out with a fix for format swapping.

brandonkelly avatar Aug 08 '23 16:08 brandonkelly