Make WordPress Core


Ignore:
Timestamp:
11/30/2014 07:53:18 PM (10 years ago)
Author:
wonderboymusic
Message:

Use round() instead of floor() when resizing image dimensions.

Updates unit tests.

Props SergeyBiryukov, kitchin.
Fixes #18532.

File:
1 edited

Legend:

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

    r29120 r30660  
    1414        $image = $this->resize_helper( DIR_TESTDATA.'/images/test-image.jpg', 25, 25 );
    1515
    16         $this->assertEquals( 'test-image-25x25.jpg', basename($image) );
     16        $this->assertEquals( 'test-image-25x25.jpg', basename( $image ) );
    1717        list($w, $h, $type) = getimagesize($image);
    1818        $this->assertEquals( 25, $w );
     
    2626        $image = $this->resize_helper( DIR_TESTDATA.'/images/test-image.png', 25, 25 );
    2727
    28         $this->assertEquals( 'test-image-25x25.png', basename($image) );
     28        if ( ! is_string( $image ) ) {  // WP_Error, stop GLib-GObject-CRITICAL assertion
     29            $this->markTestSkipped( sprintf( 'No PNG support in the editor engine %s on this system', $this->editor_engine ) );
     30            return;
     31        }
     32
     33        $this->assertEquals( 'test-image-25x25.png', basename( $image ) );
    2934        list($w, $h, $type) = getimagesize($image);
    3035        $this->assertEquals( 25, $w );
     
    3843        $image = $this->resize_helper( DIR_TESTDATA.'/images/test-image.gif', 25, 25 );
    3944
    40         $this->assertEquals( 'test-image-25x25.gif', basename($image) );
     45        if ( ! is_string( $image ) ) {  // WP_Error, stop GLib-GObject-CRITICAL assertion
     46            $this->markTestSkipped( sprintf( 'No GIF support in the editor engine %s on this system', $this->editor_engine ) );
     47            return;
     48        }
     49
     50        $this->assertEquals( 'test-image-25x25.gif', basename( $image ) );
    4151        list($w, $h, $type) = getimagesize($image);
    4252        $this->assertEquals( 25, $w );
     
    5868        $image = $this->resize_helper( DIR_TESTDATA.'/images/2007-06-17DSC_4173.JPG', 128, 96 );
    5969
    60         $this->assertEquals( '2007-06-17DSC_4173-63x96.jpg', basename($image) );
     70        $this->assertEquals( '2007-06-17DSC_4173-64x96.jpg', basename( $image ) );
    6171        list($w, $h, $type) = getimagesize($image);
    62         $this->assertEquals( 63, $w );
     72        $this->assertEquals( 64, $w );
    6373        $this->assertEquals( 96, $h );
    6474        $this->assertEquals( IMAGETYPE_JPEG, $type );
     
    7080        $image = $this->resize_helper( DIR_TESTDATA.'/images/2007-06-17DSC_4173.JPG', 128, 0 );
    7181
    72         $this->assertEquals( '2007-06-17DSC_4173-128x192.jpg', basename($image) );
     82        $this->assertEquals( '2007-06-17DSC_4173-128x193.jpg', basename( $image ) );
    7383        list($w, $h, $type) = getimagesize($image);
    7484        $this->assertEquals( 128, $w );
    75         $this->assertEquals( 192, $h );
     85        $this->assertEquals( 193, $h );
    7686        $this->assertEquals( IMAGETYPE_JPEG, $type );
    7787
     
    8292        $image = $this->resize_helper( DIR_TESTDATA.'/images/2007-06-17DSC_4173.JPG', 0, 96 );
    8393
    84         $this->assertEquals( '2007-06-17DSC_4173-63x96.jpg', basename($image) );
     94        $this->assertEquals( '2007-06-17DSC_4173-64x96.jpg', basename( $image ) );
    8595        list($w, $h, $type) = getimagesize($image);
    86         $this->assertEquals( 63, $w );
     96        $this->assertEquals( 64, $w );
    8797        $this->assertEquals( 96, $h );
    8898        $this->assertEquals( IMAGETYPE_JPEG, $type );
     
    94104        $image = $this->resize_helper( DIR_TESTDATA.'/images/2007-06-17DSC_4173.JPG', 150, 150, true );
    95105
    96         $this->assertEquals( '2007-06-17DSC_4173-150x150.jpg', basename($image) );
     106        $this->assertEquals( '2007-06-17DSC_4173-150x150.jpg', basename( $image ) );
    97107        list($w, $h, $type) = getimagesize($image);
    98108        $this->assertEquals( 150, $w );
     
    106116        $image = $this->resize_helper( DIR_TESTDATA.'/images/2007-06-17DSC_4173.JPG', 150, 100, true );
    107117
    108         $this->assertEquals( '2007-06-17DSC_4173-150x100.jpg', basename($image) );
     118        $this->assertEquals( '2007-06-17DSC_4173-150x100.jpg', basename( $image ) );
    109119        list($w, $h, $type) = getimagesize($image);
    110120        $this->assertEquals( 150, $w );
     
    118128        $image = $this->resize_helper( DIR_TESTDATA.'/images/2007-06-17DSC_4173.JPG', 50, 150, true );
    119129
    120         $this->assertEquals( '2007-06-17DSC_4173-50x150.jpg', basename($image) );
     130        $this->assertEquals( '2007-06-17DSC_4173-50x150.jpg', basename( $image ) );
    121131        list($w, $h, $type) = getimagesize($image);
    122132        $this->assertEquals( 50, $w );
     
    143153     */
    144154    public function test_resize_bad_image() {
     155
     156        if ( $this->editor_engine == 'WP_Image_Editor_Imagick' ) {
     157            $this->markTestSkipped( sprintf( 'Avoid GLib-GObject-CRITICAL assertion in %s', $this->editor_engine ) );
     158            return;
     159        }
     160
    145161        $image = $this->resize_helper( DIR_TESTDATA.'/export/crazy-cdata.xml', 25, 25 );
    146162        $this->assertInstanceOf( 'WP_Error', $image );
Note: See TracChangeset for help on using the changeset viewer.