[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
Mon Dec 2 00:42:20 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.3.1
Component:  Media                                |     Version:  4.5
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch 2nd-opinion needs-testing  |     Focuses:
-------------------------------------------------+---------------------

Comment (by vanyukov):

 @azaozz,

 I think it's a bit wrong, at least, from the original intention. Images
 are upscaled up to smooth out the edges during resizing. If we have a 5x
 larger image - just skip resample and resize, if we don't - resample the
 original and ''then'' resize.

 >Resizing a 1000x500 image to 300x150 doesn't resample the source. The
 resampled image would be larger than the original: 1500x750, $resize_ratio
 is 2.25.
 Exactly the point - we **should** resample the original.

 Also, tetsted the above fix, and these sizes fail:
 * Resizing a 10315x7049 image to 150x150 **does** resample the source. The
 {{{$resize_ratio}}} is {{{0.0077361660674977}}}. No need to resample, we
 have a huge original we can resize from.
 * Resizing a 10315x7049 image to 300x205 **does** resample the source. The
 {{{$resize_ratio}}} is {{{0.021145520584494}}}. Same thing.
 * Resizing a 10315x7049 image to 2100x1435 **does not** resample the
 source. The {{{$resize_ratio}}} is {{{1.0361305086402}}}

 In my initial proposal, I've suggested having a dynamic
 {{{$sample_factor}}}. It doesn't have to be with {{{do...while}}}, but
 just not resample all the images to 5x size.

 For example, 2100x1435 is just a bit off from being 5x smaller than
 10315x7049.
 {{{(10315x7049)-(2100x1435*25) = 2627065}}}, so we can just resample the
 original to x1.01791 the size and the resize from that image. Does that
 make sense?

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/48842#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list