Make WordPress Core

Ticket #14106: image_resize_post_process.diff

File image_resize_post_process.diff, 3.8 KB (added by nkuttler, 14 years ago)

First draft, make post-processing and renaming of thumbnails possible depending on named image_size

  • wp-admin/includes/image-edit.php

    diff --git a/wp-admin/includes/image-edit.php b/wp-admin/includes/image-edit.php
    index e871ae5..1fe412a 100644
    a b function wp_save_image($post_id) { 
    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                        $resized = image_make_intermediate_size($new_path, get_option("{$size}_size_w"), get_option("{$size}_size_h"), $crop, $size );
    634634
    635635                        if ( $resized )
    636636                                $meta['sizes'][$size] = $resized;
  • wp-admin/includes/image.php

    diff --git a/wp-admin/includes/image.php b/wp-admin/includes/image.php
    index 44329c0..f2671b3 100644
    a b function wp_generate_attachment_metadata( $attachment_id, $file ) { 
    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                        $resized = image_make_intermediate_size( $file, $size_data['width'], $size_data['height'], $size_data['crop'], $size );
    126126                        if ( $resized )
    127127                                $metadata['sizes'][$size] = $resized;
    128128                }
  • wp-includes/media.php

    diff --git a/wp-includes/media.php b/wp-includes/media.php
    index 5358b6e..67964b0 100644
    a b function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop = fal 
    402402 * @param int $jpeg_quality Optional, default is 90. Image quality percentage.
    403403 * @return mixed WP_Error on failure. String with new destination path.
    404404 */
    405 function image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90 ) {
     405function image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90, $size_name = '' ) {
    406406
    407407        $image = wp_load_image( $file );
    408408        if ( !is_resource( $image ) )
    function image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $de 
    426426        if ( IMAGETYPE_PNG == $orig_type && function_exists('imageistruecolor') && !imageistruecolor( $image ) )
    427427                imagetruecolortopalette( $newimage, false, imagecolorstotal( $image ) );
    428428
     429        // apply size-specific filters to the image
     430        if ( $size_name )
     431                $newimage = apply_filters( "image_resize_{$size_name}", $newimage );
     432
    429433        // we don't need the original in memory anymore
    430434        imagedestroy( $image );
    431435
    function image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $de 
    433437        if ( !$suffix )
    434438                $suffix = "{$dst_w}x{$dst_h}";
    435439
     440        // apply size-specific filters to the image suffix
     441        if ( $size_name )
     442                $suffix = apply_filters( "image_resize_suffix_{$size_name}", $suffix );
     443
    436444        $info = pathinfo($file);
    437445        $dir = $info['dirname'];
    438446        $ext = $info['extension'];
    function image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $de 
    477485 * @param int $width Image width.
    478486 * @param int $height Image height.
    479487 * @param bool $crop Optional, default is false. Whether to crop image to specified height and width or resize.
     488 * @param string $size Optional, default is ''. Size of image.
    480489 * @return bool|array False, if no image was created. Metadata array on success.
    481490 */
    482 function image_make_intermediate_size($file, $width, $height, $crop=false) {
     491function image_make_intermediate_size($file, $width, $height, $crop=false, $size = '' ) {
    483492        if ( $width || $height ) {
    484                 $resized_file = image_resize($file, $width, $height, $crop);
     493                $resized_file = image_resize($file, $width, $height, $crop, null, null, 90, $size);
    485494                if ( !is_wp_error($resized_file) && $resized_file && $info = getimagesize($resized_file) ) {
    486495                        $resized_file = apply_filters('image_make_intermediate_size', $resized_file);
    487496                        return array(