Make WordPress Core


Ignore:
Timestamp:
12/04/2013 10:48:45 PM (12 years ago)
Author:
nacin
Message:

Improvements to image quality handling in the image editor classes.

props markoheijnen, DH-Shredder.
fixes #25721.

File:
1 edited

Legend:

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

    r25728 r26645  
    120120            return new WP_Error( 'error_loading_image', __('File doesn’t exist?'), $this->file );
    121121
     122        /** This filter is documented in wp-includes/class-wp-image-editor-imagick.php */
    122123        // Even though Imagick uses less PHP memory than GD, set higher limit for users that have low PHP.ini limits
    123124        @ini_set( 'memory_limit', apply_filters( 'image_memory_limit', WP_MAX_MEMORY_LIMIT ) );
     
    143144                return $updated_size;
    144145
    145         return $this->set_quality();
     146        return $this->set_quality( $this->quality );
    146147    }
    147148
     
    153154     *
    154155     * @param int $quality Compression Quality. Range: [1,100]
    155      * @return boolean|WP_Error
     156     * @return boolean|WP_Error True if set successfully; WP_Error on failure.
    156157     */
    157158    public function set_quality( $quality = null ) {
    158         if ( !$quality )
     159        $quality_result = parent::set_quality( $quality );
     160        if ( is_wp_error( $quality_result ) ) {
     161            return $quality_result;
     162        } else {
    159163            $quality = $this->quality;
    160 
    161         try {
    162             if( 'image/jpeg' == $this->mime_type ) {
    163                 $this->image->setImageCompressionQuality( apply_filters( 'jpeg_quality', $quality, 'image_resize' ) );
     164        }
     165
     166        try {
     167            if ( 'image/jpeg' == $this->mime_type ) {
     168                $this->image->setImageCompressionQuality( $quality );
    164169                $this->image->setImageCompression( imagick::COMPRESSION_JPEG );
    165170            }
     
    172177        }
    173178
    174         return parent::set_quality( $quality );
     179        return true;
    175180    }
    176181
     
    448453        @ chmod( $filename, $perms );
    449454
     455        /** This filter is documented in wp-includes/class-wp-image-editor-gd.php */
    450456        return array(
    451             'path' => $filename,
    452             'file' => wp_basename( apply_filters( 'image_make_intermediate_size', $filename ) ),
    453             'width' => $this->size['width'],
    454             'height' => $this->size['height'],
     457            'path'      => $filename,
     458            'file'      => wp_basename( apply_filters( 'image_make_intermediate_size', $filename ) ),
     459            'width'     => $this->size['width'],
     460            'height'    => $this->size['height'],
    455461            'mime-type' => $mime_type,
    456462        );
Note: See TracChangeset for help on using the changeset viewer.