Make WordPress Core

Ticket #37549: image.php.patch

File image.php.patch, 1.3 KB (added by sterlo, 7 years ago)

Patch that introduces optional parameter.

  • wp-admin/includes/image.php

    diff --git wp-admin/includes/image.php wp-admin/includes/image.php
    index 4d9e076..6cf8502 100644
    function wp_crop_image( $src, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $s 
    7373 * @param string $file Filepath of the Attached image.
    7474 * @return mixed Metadata for attachment.
    7575 */
    76 function wp_generate_attachment_metadata( $attachment_id, $file ) {
     76function wp_generate_attachment_metadata( $attachment_id, $file, $dimensions = false ) {
    7777        $attachment = get_post( $attachment_id );
    7878
    7979        $metadata = array();
    8080        $support = false;
    81         if ( preg_match('!^image/!', get_post_mime_type( $attachment )) && file_is_displayable_image($file) ) {
    82                 $imagesize = getimagesize( $file );
    83                 $metadata['width'] = $imagesize[0];
    84                 $metadata['height'] = $imagesize[1];
     81        if ( preg_match( '!^image/!', get_post_mime_type( $attachment ) ) && ( file_is_displayable_image( $file ) || $dimensions ) ) {
     82                if( ! $dimensions ) {
     83                        $imagesize = getimagesize( $file );
     84                        $metadata['width'] = $imagesize[0];
     85                        $metadata['height'] = $imagesize[1];
     86                } else {
     87                        $metadata['width'] = $dimensions['width'];
     88                        $metadata['height'] = $dimensions['height'];
     89                }
    8590
    8691                // Make the file path relative to the upload dir.
    8792                $metadata['file'] = _wp_relative_upload_path($file);