WordPress.org

Make WordPress Core

Ticket #13411: transparancy.patch

File transparancy.patch, 1.7 KB (added by ocean90, 8 years ago)
  • wp-admin/includes/image.php

     
    4141 * @param int $dst_h The destination height.
    4242 * @param int $src_abs Optional. If the source crop points are absolute.
    4343 * @param string $dst_file Optional. The destination file to write to.
     44 * @param bool $dst_transparency Optional. The destination file type. Transparency = PNG.
    4445 * @return string|WP_Error|false New filepath on success, WP_Error or false on failure.
    4546 */
    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 ) {
     47function 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 ) {
    4748        if ( is_numeric( $src_file ) ) // Handle int as attachment ID
    4849                $src_file = get_attached_file( $src_file );
    4950
     
    6364                imageantialias( $dst, true );
    6465
    6566        imagecopyresampled( $dst, $src, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h );
    66 
    6767        imagedestroy( $src ); // Free up memory
    6868
    6969        if ( ! $dst_file )
    7070                $dst_file = str_replace( basename( $src_file ), 'cropped-' . basename( $src_file ), $src_file );
    7171
    72         $dst_file = preg_replace( '/\\.[^\\.]+$/', '.jpg', $dst_file );
     72        $type = '.jpeg';
     73        if ( $dst_transparency )
     74                $type = '.png';
    7375
    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) )
    7579                return $dst_file;
     80        elseif ( imagejpeg( $dst, $dst_file) )
     81                return $dst_file;
    7682        else
    7783                return false;
    7884}