Make WordPress Core

Ticket #20555: 20555.3.patch

File 20555.3.patch, 2.7 KB (added by SergeyBiryukov, 13 years ago)
  • 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                );
  • wp-admin/includes/image.php

     
    4444 * @return string|WP_Error|false New filepath on success, WP_Error or false on failure.
    4545 */
    4646function wp_crop_image( $src, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false ) {
     47        if ( 0 == $src_x && 0 == $src_y && $src_w == $dst_w && $src_h == $dst_h )
     48                return ( is_numeric( $src ) ) ? get_attached_file( $src ) : $src;
     49
    4750        if ( is_numeric( $src ) ) { // Handle int as attachment ID
    4851                $src_file = get_attached_file( $src );
    4952                if ( ! file_exists( $src_file ) ) {
    5053                        // If the file doesn't exist, attempt a url fopen on the src link.
    5154                        // This can occur with certain file replication plugins.
    5255                        $post = get_post( $src );
     56                        $image_type = $post->post_mime_type;
    5357                        $src = load_image_to_edit( $src, $post->post_mime_type, 'full' );
    5458                } else {
     59                        $size = @getimagesize( $src_file );
     60                        $image_type = ( $size ) ? $size['mime'] : '';
    5561                        $src = wp_load_image( $src_file );
    5662                }
    5763        } else {
     64                $size = @getimagesize( $src );
     65                $image_type = ( $size ) ? $size['mime'] : '';
    5866                $src = wp_load_image( $src );
    5967        }
    6068
     
    7886        if ( ! $dst_file )
    7987                $dst_file = str_replace( basename( $src_file ), 'cropped-' . basename( $src_file ), $src_file );
    8088
    81         $dst_file = preg_replace( '/\\.[^\\.]+$/', '.jpg', $dst_file );
     89        if ( 'image/png' != $image_type )
     90                $dst_file = preg_replace( '/\\.[^\\.]+$/', '.jpg', $dst_file );
    8291
    8392        // The directory containing the original file may no longer exist when
    8493        // using a replication plugin.
    8594        wp_mkdir_p( dirname( $dst_file ) );
    8695
    87         if ( imagejpeg( $dst, $dst_file, apply_filters( 'jpeg_quality', 90, 'wp_crop_image' ) ) )
     96        if ( 'image/png' == $image_type && imagepng( $dst, $dst_file ) )
    8897                return $dst_file;
     98        elseif ( imagejpeg( $dst, $dst_file, apply_filters( 'jpeg_quality', 90, 'wp_crop_image' ) ) )
     99                return $dst_file;
    89100        else
    90101                return false;
    91102}