[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
Sat Nov 30 19:28:22 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:  normal        |   Milestone:  5.3.1
Component:  Media         |     Version:  4.5
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+---------------------

Comment (by azaozz):

 Looking at:

 {{{
 /*
  * To be more efficient, resample large images to 5x the destination size
 before resizing
  * whenever the output size is less that 1/3 of the original image size
 (1/3^2 ~= .111),
  * unless we would be resampling to a scale smaller than 128x128.
  */
 if ( is_callable( array( $this->image, 'sampleImage' ) ) ) {
         $resize_ratio  = ( $dst_w / $this->size['width'] ) * ( $dst_h /
 $this->size['height'] );
         $sample_factor = 5;

         if ( $resize_ratio < .111 && ( $dst_w * $sample_factor > 128 &&
 $dst_h * $sample_factor > 128 ) ) {
                 $this->image->sampleImage( $dst_w * $sample_factor, $dst_h
 * $sample_factor );
         }
 }
 }}}

 The reason the resampling is done is to make creating much smaller sub-
 sizes more efficient. It is still another "operation" on the source that
 takes time and server resources to do. If I understand the initial
 intentions correctly,
 {{{
 whenever the output size is less that 1/3 of the original image size
 }}}

 should be
 {{{
 whenever the resampled source size is less that 1/3 of the original image
 size
 }}}

 Then the `$resize_ratio` calculation should be done with `$dst_w *
 $sample_factor` and `$dst_h * $sample_factor`. This will also be inline
 with `...unless we would be resampling to a scale smaller than 128x128`.

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


More information about the wp-trac mailing list