WordPress.org

Make WordPress Core


Ignore:
Timestamp:
03/08/2014 06:13:27 AM (6 years ago)
Author:
nacin
Message:

Allow $crop in add_image_size() to receive crop anchors (top, left, right, bottom, center).

This also applies to set_post_thumbnail_size() and image_resize_dimensions().

props bradt, wonderboymusic, DH-Shredder.
fixes #19393.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/image/dimensions.php

    r25002 r27472  
    129129    }
    130130
     131    /**
     132     * @ticket 19393
     133     */
     134    function test_crop_anchors() {
     135        // landscape: crop 640x480 to fit 400x500: 400x400 taken from a 480x480 crop
     136        // src_x = 0 (left), src_y = 0 (top)
     137        $out = image_resize_dimensions(640, 480, 400, 500, array( 'left', 'top' ) );
     138        // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h
     139        $this->assertEquals( array(0, 0, 0, 0, 400, 480, 400, 480), $out );
     140
     141        // portrait: resize 480x640 to fit 400x400: 400x400 taken from a 480x480 crop
     142        // src_x = 0 (left), src_y = 0 (top)
     143        $out = image_resize_dimensions(480, 640, 400, 500, array( 'left', 'top' ) );
     144        // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h
     145        $this->assertEquals( array(0, 0, 0, 0, 400, 500, 480, 600), $out );
     146
     147        // landscape: crop 640x480 to fit 400x500: 400x400 taken from a 480x480 crop
     148        // src_x = 240 (left), src_y = 0 (due to landscape crop)
     149        $out = image_resize_dimensions(640, 480, 400, 500, array( 'right', 'bottom' ) );
     150        // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h
     151        $this->assertEquals( array(0, 0, 240, 0, 400, 480, 400, 480), $out );
     152
     153        // portrait: resize 480x640 to fit 400x400: 400x400 taken from a 480x480 crop
     154        // src_x = 0 (due to portrait crop), src_y = 40 (bottom)
     155        $out = image_resize_dimensions(480, 640, 400, 500, array( 'right', 'bottom' ) );
     156        // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h
     157        $this->assertEquals( array(0, 0, 0, 40, 400, 500, 480, 600), $out );
     158    }
     159
    131160}
Note: See TracChangeset for help on using the changeset viewer.