Ticket #12120: force_image_resize.diff
File force_image_resize.diff, 5.2 KB (added by , 15 years ago) |
---|
-
wp-includes/media.php
275 275 * @param int $orig_h Original height. 276 276 * @param int $dest_w New width. 277 277 * @param int $dest_h New height. 278 * @param bool $ crop Optional, default is false. Whether to crop image or resize.279 * @return bool|array False, on failure. Returned array matches parameters for imagecopyresampled() PHP function.278 * @param bool $force Optional, default is false. Forces the generation of a new image, even if the original image is the same size or smaller. 279 * @return bool|array False, if no image was created. Returned array matches parameters for imagecopyresampled() PHP function. 280 280 */ 281 function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop = false ) {281 function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop = false, $force = false) { 282 282 283 283 if ($orig_w <= 0 || $orig_h <= 0) 284 284 return false; … … 318 318 list( $new_w, $new_h ) = wp_constrain_dimensions( $orig_w, $orig_h, $dest_w, $dest_h ); 319 319 } 320 320 321 // if the resulting image would be the same size or larger we don't want to resize it 322 if ( $new_w >= $orig_w && $new_h >= $orig_h ) 321 // if the resulting image would be the same size or larger, we don't want to 322 // resize it unless $force has been set 323 if ( $force == false && $new_w >= $orig_w && $new_h >= $orig_h ) 323 324 return false; 324 325 325 326 // the return array matches the parameters to imagecopyresampled() … … 348 349 * @param string $suffix Optional. File Suffix. 349 350 * @param string $dest_path Optional. New image file path. 350 351 * @param int $jpeg_quality Optional, default is 90. Image quality percentage. 351 * @return mixed WP_Error on failure. String with new destination path. Array of dimensions from {@link image_resize_dimensions()} 352 * @param bool $force Optional, default is false. Forces the generation of a new image, even if the original image is the same size or smaller. 353 * @return mixed WP_Error on failure. False, if no image was created. String with new destination path. Array of dimensions from {@link image_resize_dimensions()} 352 354 */ 353 function image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90 ) {355 function image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90, $force = false ) { 354 356 355 357 $image = wp_load_image( $file ); 356 358 if ( !is_resource( $image ) ) … … 361 363 return new WP_Error('invalid_image', __('Could not read image size'), $file); 362 364 list($orig_w, $orig_h, $orig_type) = $size; 363 365 364 $dims = image_resize_dimensions($orig_w, $orig_h, $max_w, $max_h, $crop );366 $dims = image_resize_dimensions($orig_w, $orig_h, $max_w, $max_h, $crop, $force); 365 367 if ( !$dims ) 366 368 return $dims; 367 369 list($dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) = $dims; … … 425 427 * @param int $width Image width. 426 428 * @param int $height Image height. 427 429 * @param bool $crop Optional, default is false. Whether to crop image to specified height and width or resize. 430 * @param bool $force Optional, default is false. Forces the generation of a new image, even if the original image is the same size or smaller. 428 431 * @return bool|array False, if no image was created. Metadata array on success. 429 432 */ 430 function image_make_intermediate_size($file, $width, $height, $crop =false) {433 function image_make_intermediate_size($file, $width, $height, $crop = false, $force = false) { 431 434 if ( $width || $height ) { 432 $resized_file = image_resize($file, $width, $height, $crop );435 $resized_file = image_resize($file, $width, $height, $crop, null, null, 90, $force); 433 436 if ( !is_wp_error($resized_file) && $resized_file && $info = getimagesize($resized_file) ) { 434 437 $resized_file = apply_filters('image_make_intermediate_size', $resized_file); 435 438 return array( -
wp-admin/includes/image-edit.php
630 630 } 631 631 632 632 $crop = $nocrop ? false : get_option("{$size}_crop"); 633 $resized = image_make_intermediate_size($new_path, get_option("{$size}_size_w"), get_option("{$size}_size_h"), $crop ); 633 $force = apply_filters('force_image_resize', false, $size); 634 $resized = image_make_intermediate_size($new_path, get_option("{$size}_size_w"), get_option("{$size}_size_h"), $crop, $force ); 634 635 635 636 if ( $resized ) 636 637 $meta['sizes'][$size] = $resized; -
wp-admin/includes/image.php
122 122 $sizes = apply_filters( 'intermediate_image_sizes_advanced', $sizes ); 123 123 124 124 foreach ($sizes as $size => $size_data ) { 125 $resized = image_make_intermediate_size( $file, $size_data['width'], $size_data['height'], $size_data['crop'] ); 125 $force = apply_filters('force_image_resize', false, $size); 126 $resized = image_make_intermediate_size( $file, $size_data['width'], $size_data['height'], $size_data['crop'], $force ); 126 127 if ( $resized ) 127 128 $metadata['sizes'][$size] = $resized; 128 129 }