Make WordPress Core

Changes between Initial Version and Version 6 of Ticket #40370


Ignore:
Timestamp:
10/10/2018 03:20:07 AM (7 years ago)
Author:
peterwilsoncc
Comment:

I've hit this recently too, the problem occurs during the upload process.

Using the crop names in the original report, the three images result in the same file name. During resize newscentered is saved, it's then replaced by the newstop crop which is in turn replaced by the newsbottom crop.

While site owners don't get the crops they expect, a side-effect is the srcset for an image may contain different crop orientations.

I suggest files be saved with an eight character hash of the crop information returned by image_resize_dimensions() to ensure neither of these problems occur. The file name could be uploaded-name-c{$hash}.ext.

image_resize_dimensions()'s return array is:

<?php

$dims = [
  0 => 0 
  1 => 0 
  2 => // Crop start X axis
  3 => // Crop start Y axis
  4 => // New width
  5 => // New height
  6 => // Crop width on source image
  7 => // Crop height on source image
];

The crop hash could be generated from $source_w,$source_h,$dims[2],$dims[3],$dims[6],$dims[7]. This will ensure images from the same source with the same aspect ratio and crop will end up with the same hash.

If the final two values are the same as the source image then no hash is required.

When generating the srcset in wp_calculate_image_srcset() the crop hash can be checked in the same way as that the edit suffix is checked.

In terms of backward compatibility I don't think there are implications as previously uploaded images will not have a crop hash.

cc @joemcgill as we've discussed this previously.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #40370

    • Property Keywords dev-feedback added
    • Property Focuses administration removed
    • Property Type changed from defect (bug) to enhancement
    • Property Version changed from 4.7.3 to 2.9
  • Ticket #40370 – Description

    initial v6  
    88
    99
    10 Now, whenever i use the the_post_thumbnail() with the name of my custom image size i always get the same image, cropped to the default Wordpress crop position of ('center', 'center') .
     10Now, whenever i use the the_post_thumbnail() with the name of my custom image size i always get the same image, cropped to the default WordPress crop position of ('center', 'center') .
    1111
    1212Why is that happening? I did 'refresh' the thumbnails and tried also uploading fresh image files and still i can't get 3 differently cropped versions of the image.