WordPress.org

Make WordPress Core

Changeset 29834


Ignore:
Timestamp:
10/04/2014 01:11:38 PM (5 years ago)
Author:
SergeyBiryukov
Message:

Fix setting default quality in WP_Image_Editor.

props markoheijnen.
fixes #29856 for trunk.

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-image-editor-gd.php

    r29345 r29834  
    115115        $this->mime_type = $size['mime'];
    116116
    117         return true;
     117        return $this->set_quality();
    118118    }
    119119
  • trunk/src/wp-includes/class-wp-image-editor-imagick.php

    r28879 r29834  
    141141
    142142        $updated_size = $this->update_size();
    143         if ( is_wp_error( $updated_size ) )
    144                 return $updated_size;
    145 
    146         return true;
     143        if ( is_wp_error( $updated_size ) ) {
     144            return $updated_size;
     145        }
     146
     147        return $this->set_quality();
    147148    }
    148149
  • trunk/src/wp-includes/class-wp-image-editor.php

    r28879 r29834  
    237237                 */
    238238                $quality = apply_filters( 'jpeg_quality', $quality, 'image_resize' );
    239 
    240                 if ( ! $this->set_quality( $quality ) ) {
    241                     $this->quality = $this->default_quality;
    242                 }
     239            }
     240
     241            if ( ! $this->set_quality( $quality ) ) {
     242                $this->quality = $this->default_quality;
    243243            }
    244244        }
     
    257257     */
    258258    public function set_quality( $quality = null ) {
     259        if ( null === $quality ) {
     260            $quality = $this->default_quality;
     261        }
     262
    259263        // Allow 0, but squash to 1 due to identical images in GD, and for backwards compatibility.
    260         if ( $quality == 0 ) {
     264        if ( 0 === $quality ) {
    261265            $quality = 1;
    262266        }
  • trunk/tests/phpunit/tests/image/editor.php

    r28879 r29834  
    5353        $editor = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' );
    5454
     55        // Check default value
     56        $this->assertEquals( 90, $editor->get_quality() );
     57
    5558        // Ensure set_quality works
    5659        $this->assertTrue( $editor->set_quality( 75 ) );
     
    6063        $func = create_function( '', "return 100;");
    6164        add_filter( 'wp_editor_set_quality', $func );
    62         $this->assertTrue( $editor->set_quality( 75 ) );
    63         $this->assertEquals( 75, $editor->get_quality() );
     65        $this->assertTrue( $editor->set_quality( 70 ) );
     66        $this->assertEquals( 70, $editor->get_quality() );
    6467
    6568        // Clean up
  • trunk/tests/phpunit/tests/image/editor_gd.php

    r29120 r29834  
    464464
    465465        $editor = wp_get_image_editor( $file );
     466
     467        $this->assertNotInstanceOf( 'WP_Error', $editor );
     468
    466469        $editor->load();
    467470        $editor->resize( 5, 5 );
     
    484487
    485488        $editor = wp_get_image_editor( $file );
     489
     490        $this->assertNotInstanceOf( 'WP_Error', $editor );
     491
    486492        $editor->load();
    487493
  • trunk/tests/phpunit/tests/image/editor_imagick.php

    r29120 r29834  
    464464
    465465        $editor = wp_get_image_editor( $file );
     466
     467        $this->assertNotInstanceOf( 'WP_Error', $editor );
     468       
    466469        $editor->load();
    467470        $editor->resize( 5, 5 );
     
    484487
    485488        $editor = wp_get_image_editor( $file );
     489
     490        $this->assertNotInstanceOf( 'WP_Error', $editor );
     491
    486492        $editor->load();
    487493
  • trunk/tests/phpunit/tests/image/functions.php

    r29120 r29834  
    225225            // Save the image as each file extension, check the mime type
    226226            $img = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' );
     227            $this->assertNotInstanceOf( 'WP_Error', $img );
     228
    227229            $temp = get_temp_dir();
    228230            foreach ( $mime_types as $ext => $mime_type ) {
Note: See TracChangeset for help on using the changeset viewer.