Make WordPress Core

Ticket #29856: 29856.diff

File 29856.diff, 5.0 KB (added by markoheijnen, 10 years ago)
  • src/wp-includes/class-wp-image-editor-gd.php

     
    114114                $this->update_size( $size[0], $size[1] );
    115115                $this->mime_type = $size['mime'];
    116116
    117                 return true;
     117                return $this->set_quality();
    118118        }
    119119
    120120        /**
  • src/wp-includes/class-wp-image-editor-imagick.php

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

     
    236236                                 * @param string $context Context of the filter.
    237237                                 */
    238238                                $quality = apply_filters( 'jpeg_quality', $quality, 'image_resize' );
     239                        }
    239240
    240                                 if ( ! $this->set_quality( $quality ) ) {
    241                                         $this->quality = $this->default_quality;
    242                                 }
     241                        if ( ! $this->set_quality( $quality ) ) {
     242                                $this->quality = $this->default_quality;
    243243                        }
    244244                }
    245245
     
    256256         * @return boolean|WP_Error True if set successfully; WP_Error on failure.
    257257         */
    258258        public function set_quality( $quality = null ) {
     259                if ( $quality == null ) {
     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 ( $quality === 0 ) {
    261265                        $quality = 1;
    262266                }
    263267
  • tests/phpunit/tests/image/editor.php

     
    5252                // Get an editor
    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 ) );
    5760                $this->assertEquals( 75, $editor->get_quality() );
     
    5962                // Ensure the quality filter works
    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
    6669                remove_filter( 'wp_editor_set_quality', $func );
  • tests/phpunit/tests/image/editor_gd.php

     
    463463                $file = DIR_TESTDATA . '/images/transparent.png';
    464464
    465465                $editor = wp_get_image_editor( $file );
     466
     467                $this->assertNotInstanceOf( 'WP_Error', $editor );
     468
    466469                $editor->load();
    467470                $editor->resize( 5, 5 );
    468471                $save_to_file = tempnam( get_temp_dir(), '' ) . '.png';
     
    483486                $file = DIR_TESTDATA . '/images/transparent.png';
    484487
    485488                $editor = wp_get_image_editor( $file );
     489
     490                $this->assertNotInstanceOf( 'WP_Error', $editor );
     491
    486492                $editor->load();
    487493
    488494                $save_to_file = tempnam( get_temp_dir(), '' ) . '.png';
  • tests/phpunit/tests/image/editor_imagick.php

     
    463463                $file = DIR_TESTDATA . '/images/transparent.png';
    464464
    465465                $editor = wp_get_image_editor( $file );
     466
     467                $this->assertNotInstanceOf( 'WP_Error', $editor );
     468               
    466469                $editor->load();
    467470                $editor->resize( 5, 5 );
    468471                $save_to_file = tempnam( get_temp_dir(), '' ) . '.png';
     
    483486                $file = DIR_TESTDATA . '/images/transparent.png';
    484487
    485488                $editor = wp_get_image_editor( $file );
     489
     490                $this->assertNotInstanceOf( 'WP_Error', $editor );
     491
    486492                $editor->load();
    487493
    488494                $save_to_file = tempnam( get_temp_dir(), '' ) . '.png';
  • tests/phpunit/tests/image/functions.php

     
    224224
    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 ) {
    229231                                $file = wp_unique_filename( $temp, uniqid() . ".$ext" );