Make WordPress Core

Ticket #13461: 13461.2.patch

File 13461.2.patch, 2.4 KB (added by SergeyBiryukov, 12 years ago)
  • wp-includes/media.php

     
    395395/**
    396396 * Scale down an image to fit a particular size and save a new copy of the image.
    397397 *
    398  * The PNG transparency will be preserved using the function, as well as the
     398 * The PNG and GIF transparency will be preserved using the function, as well as the
    399399 * image type. If the file going in is PNG, then the resized image is going to
    400400 * be PNG. The only supported image types are PNG, GIF, and JPEG.
    401401 *
     
    430430                return new WP_Error( 'error_getting_dimensions', __('Could not calculate resized image dimensions') );
    431431        list($dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) = $dims;
    432432
    433         $newimage = wp_imagecreatetruecolor( $dst_w, $dst_h );
     433        $newimage = wp_imagecreatetruecolor( $dst_w, $dst_h, $orig_type, $image );
    434434
    435435        imagecopyresampled( $newimage, $image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
    436436
     
    10191019 *
    10201020 * @param int $width Image width
    10211021 * @param int $height Image height
     1022 * @param int $image_type Image type
     1023 * @param resource $original_image Original image
    10221024 * @return image resource
    10231025 */
    1024 function wp_imagecreatetruecolor($width, $height) {
    1025         $img = imagecreatetruecolor($width, $height);
    1026         if ( is_resource($img) && function_exists('imagealphablending') && function_exists('imagesavealpha') ) {
    1027                 imagealphablending($img, false);
    1028                 imagesavealpha($img, true);
     1026function wp_imagecreatetruecolor( $width, $height, $image_type = null, $original_image = null ) {
     1027        $img = imagecreatetruecolor( $width, $height );
     1028        if ( ! is_resource( $img ) )
     1029                return false;
     1030
     1031        if ( IMAGETYPE_GIF == $image_type && is_resource( $original_image ) && function_exists( 'imagecolortransparent' ) ) {
     1032                $transparent_id = imagecolortransparent( $original_image );
     1033                if ( $transparent_id >= 0 ) {
     1034                        $transparent_color = imagecolorsforindex( $original_image, $transparent_id );
     1035                        $transparent_id = imagecolorallocate( $img, $transparent_color['red'], $transparent_color['green'], $transparent_color['blue'] );
     1036                        imagefill( $img, 0, 0, $transparent_id );
     1037                        imagecolortransparent( $img, $transparent_id );
     1038                }
     1039        } elseif ( function_exists( 'imagealphablending' ) && function_exists( 'imagesavealpha' ) ) {
     1040                imagealphablending( $img, false );
     1041                imagesavealpha( $img, true );
    10291042        }
     1043
    10301044        return $img;
    10311045}
    10321046