Don't convert png to jpg when cropping a header. Prevents stomping transparency. Props SergeyBiryukov, kovshenin. fixes #20555
git-svn-id: https://develop.svn.wordpress.org/trunk@20706 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
19842a6b22
commit
71150d164a
|
@ -858,12 +858,15 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?>
|
||||||
$parent_url = $parent->guid;
|
$parent_url = $parent->guid;
|
||||||
$url = str_replace(basename($parent_url), basename($cropped), $parent_url);
|
$url = str_replace(basename($parent_url), basename($cropped), $parent_url);
|
||||||
|
|
||||||
|
$size = @getimagesize( $cropped );
|
||||||
|
$image_type = ( $size ) ? $size['mime'] : 'image/jpeg';
|
||||||
|
|
||||||
// Construct the object array
|
// Construct the object array
|
||||||
$object = array(
|
$object = array(
|
||||||
'ID' => $attachment_id,
|
'ID' => $attachment_id,
|
||||||
'post_title' => basename($cropped),
|
'post_title' => basename($cropped),
|
||||||
'post_content' => $url,
|
'post_content' => $url,
|
||||||
'post_mime_type' => 'image/jpeg',
|
'post_mime_type' => $image_type,
|
||||||
'guid' => $url,
|
'guid' => $url,
|
||||||
'context' => 'custom-header'
|
'context' => 'custom-header'
|
||||||
);
|
);
|
||||||
|
|
|
@ -44,17 +44,25 @@ function wp_create_thumbnail( $file, $max_side, $deprecated = '' ) {
|
||||||
* @return string|WP_Error|false New filepath on success, WP_Error or false on failure.
|
* @return string|WP_Error|false New filepath on success, WP_Error or false on failure.
|
||||||
*/
|
*/
|
||||||
function wp_crop_image( $src, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false ) {
|
function wp_crop_image( $src, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false ) {
|
||||||
|
if ( 0 == $src_x && 0 == $src_y && $src_w == $dst_w && $src_h == $dst_h )
|
||||||
|
return ( is_numeric( $src ) ) ? get_attached_file( $src ) : $src;
|
||||||
|
|
||||||
if ( is_numeric( $src ) ) { // Handle int as attachment ID
|
if ( is_numeric( $src ) ) { // Handle int as attachment ID
|
||||||
$src_file = get_attached_file( $src );
|
$src_file = get_attached_file( $src );
|
||||||
if ( ! file_exists( $src_file ) ) {
|
if ( ! file_exists( $src_file ) ) {
|
||||||
// If the file doesn't exist, attempt a url fopen on the src link.
|
// If the file doesn't exist, attempt a url fopen on the src link.
|
||||||
// This can occur with certain file replication plugins.
|
// This can occur with certain file replication plugins.
|
||||||
$post = get_post( $src );
|
$post = get_post( $src );
|
||||||
|
$image_type = $post->post_mime_type;
|
||||||
$src = load_image_to_edit( $src, $post->post_mime_type, 'full' );
|
$src = load_image_to_edit( $src, $post->post_mime_type, 'full' );
|
||||||
} else {
|
} else {
|
||||||
|
$size = @getimagesize( $src_file );
|
||||||
|
$image_type = ( $size ) ? $size['mime'] : '';
|
||||||
$src = wp_load_image( $src_file );
|
$src = wp_load_image( $src_file );
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
$size = @getimagesize( $src );
|
||||||
|
$image_type = ( $size ) ? $size['mime'] : '';
|
||||||
$src = wp_load_image( $src );
|
$src = wp_load_image( $src );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,13 +86,16 @@ function wp_crop_image( $src, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $s
|
||||||
if ( ! $dst_file )
|
if ( ! $dst_file )
|
||||||
$dst_file = str_replace( basename( $src_file ), 'cropped-' . basename( $src_file ), $src_file );
|
$dst_file = str_replace( basename( $src_file ), 'cropped-' . basename( $src_file ), $src_file );
|
||||||
|
|
||||||
$dst_file = preg_replace( '/\\.[^\\.]+$/', '.jpg', $dst_file );
|
if ( 'image/png' != $image_type )
|
||||||
|
$dst_file = preg_replace( '/\\.[^\\.]+$/', '.jpg', $dst_file );
|
||||||
|
|
||||||
// The directory containing the original file may no longer exist when
|
// The directory containing the original file may no longer exist when
|
||||||
// using a replication plugin.
|
// using a replication plugin.
|
||||||
wp_mkdir_p( dirname( $dst_file ) );
|
wp_mkdir_p( dirname( $dst_file ) );
|
||||||
|
|
||||||
if ( imagejpeg( $dst, $dst_file, apply_filters( 'jpeg_quality', 90, 'wp_crop_image' ) ) )
|
if ( 'image/png' == $image_type && imagepng( $dst, $dst_file ) )
|
||||||
|
return $dst_file;
|
||||||
|
elseif ( imagejpeg( $dst, $dst_file, apply_filters( 'jpeg_quality', 90, 'wp_crop_image' ) ) )
|
||||||
return $dst_file;
|
return $dst_file;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue