WordPress.org

Make WordPress Core

Ticket #12120: force_image_resize.diff

File force_image_resize.diff, 5.2 KB (added by Kanuck54, 11 years ago)
  • wp-includes/media.php

     
    275275 * @param int $orig_h Original height.
    276276 * @param int $dest_w New width.
    277277 * @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.
    280280 */
    281 function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop = false) {
     281function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop = false, $force = false) {
    282282
    283283        if ($orig_w <= 0 || $orig_h <= 0)
    284284                return false;
     
    318318                list( $new_w, $new_h ) = wp_constrain_dimensions( $orig_w, $orig_h, $dest_w, $dest_h );
    319319        }
    320320
    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 )
    323324                return false;
    324325
    325326        // the return array matches the parameters to imagecopyresampled()
     
    348349 * @param string $suffix Optional. File Suffix.
    349350 * @param string $dest_path Optional. New image file path.
    350351 * @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()}
    352354 */
    353 function image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90 ) {
     355function image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90, $force = false ) {
    354356
    355357        $image = wp_load_image( $file );
    356358        if ( !is_resource( $image ) )
     
    361363                return new WP_Error('invalid_image', __('Could not read image size'), $file);
    362364        list($orig_w, $orig_h, $orig_type) = $size;
    363365
    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);
    365367        if ( !$dims )
    366368                return $dims;
    367369        list($dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) = $dims;
     
    425427 * @param int $width Image width.
    426428 * @param int $height Image height.
    427429 * @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.
    428431 * @return bool|array False, if no image was created. Metadata array on success.
    429432 */
    430 function image_make_intermediate_size($file, $width, $height, $crop=false) {
     433function image_make_intermediate_size($file, $width, $height, $crop = false, $force = false) {
    431434        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);
    433436                if ( !is_wp_error($resized_file) && $resized_file && $info = getimagesize($resized_file) ) {
    434437                        $resized_file = apply_filters('image_make_intermediate_size', $resized_file);
    435438                        return array(
  • wp-admin/includes/image-edit.php

     
    630630                        }
    631631
    632632                        $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 );
    634635
    635636                        if ( $resized )
    636637                                $meta['sizes'][$size] = $resized;
  • wp-admin/includes/image.php

     
    122122                $sizes = apply_filters( 'intermediate_image_sizes_advanced', $sizes );
    123123
    124124                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 );
    126127                        if ( $resized )
    127128                                $metadata['sizes'][$size] = $resized;
    128129                }