FEATURE: Add focal-point support for ImageVariants (crops) and Thumbnails #5127
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In many cases the crops taken from the center of images are not optimal and important parts of an image get lost. This pr allows to specify a focal-point for imageVariants that is later on respected when crops of the imageVariant are generated.
The implementation uses an preliminary crop for images with a focalPoint that ensures:
In addition this change calculates the focal-point and image dimensions for async thumbnails on generation. That way async thumbnails can be rendered with full width and height informations which allows to make use of those informations in the rendering to prevent layout shifts or to specify the center of an object-fit css rule.
Resolves: #2296
Required Neos.UI Changes neos/neos-ui#3835
focalPointX
?int andfocalPointY
?int of the new ImageVariant that is createdvia endpoint
neos/content/create-image-variant
which points to\Neos\Neos\Controller\Backend\ContentController::createImageVariantAction
Review instructions
!!! By intention the focal point is not added to images in the media library (yet). The main reason for that is that this would require a mechanism to re-render all thumbnails of an asset if the focal point is changed. Also i personally see more value to specify the focal point by editors for a specific crop that is why the implementation cover ImageVariants and Thumbnails. If we see value in focal point support via media library we can add this in future !!!
The main part of this solution is that the calculation of the cropped dimensions was moved out from the
ResizeImageAdjustment
to a newResizeDimensionCalculator
where it can be accessed from other code like theImageThumbnailGenerator
and theThumbnailService
that need to know about image dimensions beforehand. The tests for the now deprecated methods inResizeImageAdjustment
are still in place to prove that the calculations are the same.For now the generated thumbnails will get a small green circle rendered on the focal-point if a focal point was set. This allows to visually verify the results in a human understandable way. After approval this will be removed.
Also the tests with php 8.0 and 8.1 are failing since this will be rebased on to 8.4 once this branch is green again. I used 8.2 features that will not work with lower php versions.
Final Todos before merge - after review and general approval
Checklist
FEATURE|TASK|BUGFIX
!!!
and have upgrade-instructions