Repository navigation
Conversation
Image sub-sizes with the same dimensions but different crop positions, for example `add_image_size( 'top', 400, 400, array( 'center', 'top' ) )` and `add_image_size( 'bottom', 400, 400, array( 'center', 'bottom' ) )`, were saved to the same file name and overwrote each other. This appends a short hash of the crop position to the file name suffix when a sub-size is cropped from a position other than center. Center crops, including `crop => true`, keep their existing file names. See #40370. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @harmit001, @[email protected]. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
See #40370. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Image sub-sizes with the same dimensions but different crop positions are saved to the same file name, so each one overwrites the previous one:
All three end up as
image-400x400.jpg, and only the last crop survives.This refreshes the approach from the earlier patches on the ticket (PR #5269 no longer applies to trunk), following comment:6 and comment:7:
WP_Image_Editor::get_suffix()appends an 8-character hash of the crop position when a sub-size is cropped from a position other than center, for exampleimage-400x400-1a2b3c4d.jpg.crop => trueandarray( 'center', 'center' )) keep their existing file names, so nothing changes for existing sites, default sizes or plugins that rely on the-{width}x{height}pattern.image_resize_dimensions()handles them, so unsupported values (treated as center there) don't produce a hash.make_subsize()saves the file in the GD and Imagick editors, and is reset afterwards, so laterresize()/save()calls on the same editor are unaffected.Compared with PR #5269, this:
hashkey to the image meta,multi_resize()directly on both editors.Testing
New tests:
test_multi_resize_with_same_dimensions_and_different_crop_positionsintests/phpunit/tests/image/editorGd.phpandeditorImagick.php.Manual testing:
add_image_size()calls above to a theme'sfunctions.php.-400x400file in the uploads folder. After:-400x400.jpgplus two-400x400-{hash}.jpgfiles, each with a different crop.Trac ticket: https://core.trac.wordpress.org/ticket/40370