Make WordPress Core

Ticket #55443: 55443-fix-secondary-scaled.diff

File 55443-fix-secondary-scaled.diff, 1.8 KB (added by adamsilverstein, 2 years ago)
  • src/wp-admin/includes/image.php

    diff --git src/wp-admin/includes/image.php src/wp-admin/includes/image.php
    index 98689672b3..c2652792cb 100644
    function wp_create_image_subsizes( $file, $attachment_id ) { 
    341341        wp_update_attachment_metadata( $attachment_id, $image_meta );
    342342
    343343        if ( ! empty( $additional_mime_types ) ) {
    344                 // Use the original file's exif_meta orientation information for secondary mime generation.
    345                 $saved_orientation                       = $image_meta['image_meta']['orientation'];
     344                // Use the original file's exif_meta orientation and size information for secondary mime generation to ensure
     345                // sub-sized images are correctly scaled and rotated.
     346
     347                // Save data.
     348                $saved_meta                = array();
     349                $saved_meta['orientation'] = $image_meta['image_meta']['orientation'];
     350                $saved_meta['width']       = $image_meta['width'];
     351                $saved_meta['height']      = $image_meta['height'];
     352
     353                // Temporarily set the image meta to the original file's meta.
    346354                $image_meta['image_meta']['orientation'] = $exif_meta['orientation'];
    347                 $image_meta                              = _wp_make_additional_mime_types( $additional_mime_types, $file, $image_meta, $attachment_id );
    348                 $image_meta['image_meta']['orientation'] = $saved_orientation;
     355                $image_meta['width']                     = $imagesize[0];
     356                $image_meta['height']                    = $imagesize[1];
     357
     358                $image_meta = _wp_make_additional_mime_types( $additional_mime_types, $file, $image_meta, $attachment_id );
     359
     360                // Restore the saved meta data.
     361                $image_meta['image_meta']['orientation'] = $saved_meta['orientation'];
     362                $image_meta['width']                     = $saved_meta['width'];
     363                $image_meta['height']                    = $saved_meta['height'];
    349364
    350365        }
    351366