[wp-trac] [WordPress Trac] #48842: Fix calculation error when resampling images before resizing in class-wp-image-editor-imagick.php
WordPress Trac
noreply at wordpress.org
Tue Dec 3 22:29:24 UTC 2019
#48842: Fix calculation error when resampling images before resizing in class-wp-
image-editor-imagick.php
---------------------------------------+---------------------
Reporter: azaozz | Owner: (none)
Type: defect (bug) | Status: new
Priority: high | Milestone: 5.4
Component: Media | Version: 4.5
Severity: normal | Resolution:
Keywords: 2nd-opinion needs-testing | Focuses:
---------------------------------------+---------------------
Changes (by azaozz):
* keywords: has-patch 2nd-opinion needs-testing => 2nd-opinion needs-
testing
* milestone: 5.3.1 => 5.4
Comment:
Replying to [comment:5 vanyukov]:
> ...and there was a reference to this article:
> https://www.smashingmagazine.com/2015/06/efficient-image-resizing-with-
imagemagick/
>
> I can see that many image optimization settings are similar in
WordPress, so I assumed a lot was taken from that article.
Right, the enhancements in WP are (mostly) based on
https://github.com/nwtn/php-respimg by the same author which seem based on
the ImageMagick `-thumbnail` option:
https://github.com/ImageMagick/ImageMagick/blob/master/MagickCore/resize.c#L4491.
Looking at the ImageMagick code, it also has a hard-coded scale factor of
5 but does the resampling for a bit smaller sub-sizes, `$resize_ratio <=
0.1`. This still upscales when images are resized to between 32% to 20% of
the original.
On the other hand quickly testing this with the
[https://upload.wikimedia.org/wikipedia/commons/f/ff/Pizigani_1367_Chart_10MB.jpg
sample 10MB JPEG image] in ImageMagick 7.0.9 (PHP 7.3), the sub-size
images that were resized "directly" without the 5x scaling are either
identical or a little smaller in file size, up to about 2% smaller. This
will need a lot more testing but seems that ImageMagick perhaps handles
JPEGs better in newer versions?
Thinking we should look at preventing the upscaling when using the above
technique, at least for very large source images. Seems the "when to start
scaling" value is set to a more or less a rule-of-thumb at about 1/3 of
the original. Using that only when the required image is less than 20% of
the original may make sense.
Also tested the edge case when the upscaling makes an image larger than
the allowed image dimensions in the ImageMagick policy settings (see
https://github.com/ImageMagick/ImageMagick/blob/master/config/policy.xml).
This fails with "width or height exceeds limit" as expected.
Moving this to the 5.4 milestone as it seems to be the expected behaviour,
and will need a lot more testing and considerations to change.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/48842#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list