Make WordPress Core

Ticket #20555: 20555.2.patch

File 20555.2.patch, 2.2 KB (added by kovshenin, 13 years ago)
  • wp-admin/includes/image.php

     
    5050                        // If the file doesn't exist, attempt a url fopen on the src link.
    5151                        // This can occur with certain file replication plugins.
    5252                        $post = get_post( $src );
     53                        $image_type = $post->post_mime_type;
    5354                        $src = load_image_to_edit( $src, $post->post_mime_type, 'full' );
    5455                } else {
     56                        $size = @getimagesize( $src_file );
     57                        $image_type = ( $size ) ? $size['mime'] : '';
    5558                        $src = wp_load_image( $src_file );
    5659                }
    5760        } else {
     61                $size = @getimagesize( $src );
     62                $image_type = ( $size ) ? $size['mime'] : '';
    5863                $src = wp_load_image( $src );
    5964        }
    6065
     
    7883        if ( ! $dst_file )
    7984                $dst_file = str_replace( basename( $src_file ), 'cropped-' . basename( $src_file ), $src_file );
    8085
    81         $dst_file = preg_replace( '/\\.[^\\.]+$/', '.jpg', $dst_file );
     86        if ( 'image/png' != $image_type )
     87                $dst_file = preg_replace( '/\\.[^\\.]+$/', '.jpg', $dst_file );
    8288
    8389        // The directory containing the original file may no longer exist when
    8490        // using a replication plugin.
    8591        wp_mkdir_p( dirname( $dst_file ) );
    8692
    87         if ( imagejpeg( $dst, $dst_file, apply_filters( 'jpeg_quality', 90, 'wp_crop_image' ) ) )
     93        if ( 'image/png' == $image_type && imagepng( $dst, $dst_file ) )
    8894                return $dst_file;
     95        elseif ( imagejpeg( $dst, $dst_file, apply_filters( 'jpeg_quality', 90, 'wp_crop_image' ) ) )
     96                return $dst_file;
    8997        else
    9098                return false;
    9199}
  • wp-admin/custom-header.php

     
    858858                $parent_url = $parent->guid;
    859859                $url = str_replace(basename($parent_url), basename($cropped), $parent_url);
    860860
     861                $size = @getimagesize( $cropped );
     862                $image_type = ( $size ) ? $size['mime'] : 'image/jpeg';
     863
    861864                // Construct the object array
    862865                $object = array(
    863866                        'ID' => $attachment_id,
    864867                        'post_title' => basename($cropped),
    865868                        'post_content' => $url,
    866                         'post_mime_type' => 'image/jpeg',
     869                        'post_mime_type' => $image_type,
    867870                        'guid' => $url,
    868871                        'context' => 'custom-header'
    869872                );