Make WordPress Core

Ticket #19793: 19793.diff

File 19793.diff, 1.5 KB (added by mboynes, 9 years ago)

Fix edge-case in media cropping where selection and destination are the same size

  • src/wp-includes/media.php

     
    503503        }
    504504
    505505        // if the resulting image would be the same size or larger we don't want to resize it
    506         if ( $new_w >= $orig_w && $new_h >= $orig_h )
     506        if ( $new_w >= $orig_w && $new_h >= $orig_h && $dest_w != $orig_w && $dest_h != $orig_h ) {
    507507                return false;
     508        }
    508509
    509510        // the return array matches the parameters to imagecopyresampled()
    510511        // int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h
  • tests/phpunit/tests/image/dimensions.php

     
    128128                $this->assertEquals( array(0, 0, 0, 20, 400, 500, 480, 600), $out );
    129129        }
    130130
     131        function test_640x480() {
     132                // crop 640x480 to fit 640x480 (no change)
     133                $out = image_resize_dimensions(640, 480, 640, 480, true);
     134                // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h
     135                $this->assertEquals( array(0, 0, 0, 0, 640, 480, 640, 480), $out );
     136
     137                // resize 640x480 to fit 640x480 (no change)
     138                $out = image_resize_dimensions(640, 480, 640, 480, false);
     139                // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h
     140                $this->assertEquals( array(0, 0, 0, 0, 640, 480, 640, 480), $out );
     141        }
     142
    131143        /**
    132144         * @ticket 19393
    133145         */