WordPress.org

Make WordPress Core

Ticket #30874: media.patch

File media.patch, 1.3 KB (added by drrobotnik, 7 years ago)

modification to media.php to the image_downsize function

  • wp-includes/media.php

    diff --git a/wp-includes/media.php b/wp-includes/media.php
    index c7d092d..2609ebc 100644
    a b function image_downsize($id, $size = 'medium') { 
    171171        $is_intermediate = false;
    172172        $img_url_basename = wp_basename($img_url);
    173173
     174        if( empty( $meta['sizes'][$size] ) && in_array( $size, get_intermediate_image_sizes() ) ) {
     175
     176                global $_wp_additional_image_sizes;
     177                $upload_dir = wp_upload_dir();
     178                $size = $_wp_additional_image_sizes[ $size ];
     179                $file = $upload_dir['basedir'] . '/' . $meta['file'];
     180
     181                $intermediate = image_make_intermediate_size( $file, $size['width'], $size['height'], $size['crop'] );
     182
     183                $img_url = str_replace($img_url_basename, $intermediate['file'], $img_url);
     184                $width = $intermediate['width'];
     185                $height = $intermediate['height'];
     186                $is_intermediate = true;
     187
     188                require_once ( ABSPATH . 'wp-admin/includes/image.php' );
     189
     190                $attach_data = wp_generate_attachment_metadata( $id, $file );
     191                wp_update_attachment_metadata( $id, $attach_data );
     192
    174193        // try for a new style intermediate size
    175         if ( $intermediate = image_get_intermediate_size($id, $size) ) {
     194        }elseif ( $intermediate = image_get_intermediate_size($id, $size) ) {
    176195                $img_url = str_replace($img_url_basename, $intermediate['file'], $img_url);
    177196                $width = $intermediate['width'];
    178197                $height = $intermediate['height'];