Changeset 26645
- Timestamp:
- 12/04/2013 10:48:45 PM (11 years ago)
- Location:
- trunk/src/wp-includes
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-image-editor-gd.php
r25728 r26645 78 78 * @access protected 79 79 * 80 * @return boolean| \WP_Error80 * @return boolean|WP_Error True if loaded successfully; WP_Error on failure. 81 81 */ 82 82 public function load() { … … 87 87 return new WP_Error( 'error_loading_image', __('File doesn’t exist?'), $this->file ); 88 88 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 */ 89 96 // Set artificially high because GD uses uncompressed images in memory 90 97 @ini_set( 'memory_limit', apply_filters( 'image_memory_limit', WP_MAX_MEMORY_LIMIT ) ); 98 91 99 $this->image = @imagecreatefromstring( file_get_contents( $this->file ) ); 92 100 … … 106 114 $this->mime_type = $size['mime']; 107 115 108 return true;116 return $this->set_quality( $this->quality ); 109 117 } 110 118 … … 362 370 } 363 371 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 ) ) ) 365 373 return new WP_Error( 'image_save_error', __('Image Editor Save Failed') ); 366 374 } … … 374 382 @ chmod( $filename, $perms ); 375 383 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 */ 376 391 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, 382 397 ); 383 398 } -
trunk/src/wp-includes/class-wp-image-editor-imagick.php
r25728 r26645 120 120 return new WP_Error( 'error_loading_image', __('File doesn’t exist?'), $this->file ); 121 121 122 /** This filter is documented in wp-includes/class-wp-image-editor-imagick.php */ 122 123 // Even though Imagick uses less PHP memory than GD, set higher limit for users that have low PHP.ini limits 123 124 @ini_set( 'memory_limit', apply_filters( 'image_memory_limit', WP_MAX_MEMORY_LIMIT ) ); … … 143 144 return $updated_size; 144 145 145 return $this->set_quality( );146 return $this->set_quality( $this->quality ); 146 147 } 147 148 … … 153 154 * 154 155 * @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. 156 157 */ 157 158 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 { 159 163 $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 ); 164 169 $this->image->setImageCompression( imagick::COMPRESSION_JPEG ); 165 170 } … … 172 177 } 173 178 174 return parent::set_quality( $quality );179 return true; 175 180 } 176 181 … … 448 453 @ chmod( $filename, $perms ); 449 454 455 /** This filter is documented in wp-includes/class-wp-image-editor-gd.php */ 450 456 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'], 455 461 'mime-type' => $mime_type, 456 462 ); -
trunk/src/wp-includes/class-wp-image-editor.php
r25728 r26645 206 206 * 207 207 * @param int $quality Compression Quality. Range: [1,100] 208 * @return boolean 209 */ 210 public function set_quality( $quality ) { 208 * @return boolean|WP_Error True if set successfully; WP_Error on failure. 209 */ 210 public function set_quality( $quality = null ) { 211 if ( $quality == null ) { 212 $quality = $this->quality; 213 } 214 211 215 /** 212 216 * Filter the default quality setting. … … 214 218 * @since 3.5.0 215 219 * 216 * @param int $quality Quality level between 0(low) and 100 (high).220 * @param int $quality Quality level between 1 (low) and 100 (high). 217 221 */ 218 $this->quality = apply_filters( 'wp_editor_set_quality', $quality ); 219 220 return ( (bool) $this->quality ); 222 $quality = apply_filters( 'wp_editor_set_quality', $quality, $this->mime_type ); 223 224 /** 225 * Filter the JPEG quality for backwards compatibilty. 226 * 227 * @since 2.5.0 228 * 229 * @param int $quality Quality level between 0 (low) and 100 (high) of the JPEG. 230 * @param string The context of the filter. 231 */ 232 if ( 'image/jpeg' == $this->mime_type ) { 233 $quality = apply_filters( 'jpeg_quality', $quality, 'image_resize' ); 234 235 // Allow 0, but squash to 1 due to identical images in GD, and for backwards compatibility. 236 if ( $quality == 0 ) { 237 $quality = 1; 238 } 239 } 240 241 if ( ( $quality >= 1 ) && ( $quality <= 100 ) ){ 242 $this->quality = $quality; 243 return true; 244 } else { 245 return new WP_Error( 'invalid_image_quality', __('Attempted to set image quality outside of the range [1,100].') ); 246 } 221 247 } 222 248
Note: See TracChangeset
for help on using the changeset viewer.