Ticket #13411: transparancy.patch
| File transparancy.patch, 1.7 KB (added by ocean90, 3 years ago) |
|---|
-
wp-admin/includes/image.php
41 41 * @param int $dst_h The destination height. 42 42 * @param int $src_abs Optional. If the source crop points are absolute. 43 43 * @param string $dst_file Optional. The destination file to write to. 44 * @param bool $dst_transparency Optional. The destination file type. Transparency = PNG. 44 45 * @return string|WP_Error|false New filepath on success, WP_Error or false on failure. 45 46 */ 46 function wp_crop_image( $src_file, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false ) {47 function wp_crop_image( $src_file, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false, $dst_transparency = false ) { 47 48 if ( is_numeric( $src_file ) ) // Handle int as attachment ID 48 49 $src_file = get_attached_file( $src_file ); 49 50 … … 63 64 imageantialias( $dst, true ); 64 65 65 66 imagecopyresampled( $dst, $src, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ); 66 67 67 imagedestroy( $src ); // Free up memory 68 68 69 69 if ( ! $dst_file ) 70 70 $dst_file = str_replace( basename( $src_file ), 'cropped-' . basename( $src_file ), $src_file ); 71 71 72 $dst_file = preg_replace( '/\\.[^\\.]+$/', '.jpg', $dst_file ); 72 $type = '.jpeg'; 73 if ( $dst_transparency ) 74 $type = '.png'; 73 75 74 if ( imagejpeg( $dst, $dst_file, apply_filters( 'jpeg_quality', 90, 'wp_crop_image' ) ) ) 76 $dst_file = preg_replace( '/\\.[^\\.]+$/', $type, $dst_file ); 77 78 if ( $dst_transparency && imagepng( $dst, $dst_file) ) 75 79 return $dst_file; 80 elseif ( imagejpeg( $dst, $dst_file) ) 81 return $dst_file; 76 82 else 77 83 return false; 78 84 }
