Make WordPress Core


Ignore:
Timestamp:
12/04/2013 10:48:45 PM (13 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-gd.php

    r25728 r26645  
    7878         * @access protected
    7979         *
    80          * @return boolean|\WP_Error
     80         * @return boolean|WP_Error True if loaded successfully; WP_Error on failure.
    8181         */
    8282        public function load() {
     
    8787                        return new WP_Error( 'error_loading_image', __('File doesn’t exist?'), $this->file );
    8888
     89                /**
     90                 * Filter the memory limit allocated for image manipulation.
     91                 *
     92                 * @since 3.5.0
     93                 *
     94                 * @param int Maximum memory limit to allocate (default is WP_MAX_MEMORY_LIMIT)
     95                 */
    8996                // Set artificially high because GD uses uncompressed images in memory
    9097                @ini_set( 'memory_limit', apply_filters( 'image_memory_limit', WP_MAX_MEMORY_LIMIT ) );
     98
    9199                $this->image = @imagecreatefromstring( file_get_contents( $this->file ) );
    92100
     
    106114                $this->mime_type = $size['mime'];
    107115
    108                 return true;
     116                return $this->set_quality( $this->quality );
    109117        }
    110118
     
    362370                }
    363371                elseif ( 'image/jpeg' == $mime_type ) {
    364                         if ( ! $this->make_image( $filename, 'imagejpeg', array( $image, $filename, apply_filters( 'jpeg_quality', $this->quality, 'image_resize' ) ) ) )
     372                        if ( ! $this->make_image( $filename, 'imagejpeg', array( $image, $filename, $this->quality ) ) )
    365373                                return new WP_Error( 'image_save_error', __('Image Editor Save Failed') );
    366374                }
     
    374382                @ chmod( $filename, $perms );
    375383
     384                /**
     385                 * Filter the name of the saved image file.
     386                 *
     387                 * @since 2.6.0
     388                 *
     389                 * @param string $filename Name of the file.
     390                 */
    376391                return array(
    377                         'path' => $filename,
    378                         'file' => wp_basename( apply_filters( 'image_make_intermediate_size', $filename ) ),
    379                         'width' => $this->size['width'],
    380                         'height' => $this->size['height'],
    381                         'mime-type'=> $mime_type,
     392                        'path'      => $filename,
     393                        'file'      => wp_basename( apply_filters( 'image_make_intermediate_size', $filename ) ),
     394                        'width'     => $this->size['width'],
     395                        'height'    => $this->size['height'],
     396                        'mime-type' => $mime_type,
    382397                );
    383398        }
Note: See TracChangeset for help on using the changeset viewer.