Repository navigation
Conversation
applyCrop() computed its crop box from the cached FocusPointWidth/Height.
If these no longer match the file (e.g. after the file was replaced), the
box lay outside the image and the backend threw ("bad extract area").
Fall back to a centered crop when the backend size differs from the cached
size, and clamp getX()/getY() to [-1, 1] so DB values can never address a
point outside the image.
Contributor
Author
|
Update: the root cause is fixed in silverstripe-assets 3.3.4 (silverstripe/silverstripe-assets#725, which resets the cached image backend). This PR is still useful as a safety net for assets < 3.3.4 and for other ways the cached dimensions can go stale. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
calculateCrop()uses the cachedFocusPointWidth/FocusPointHeight, andapplyCrop()applies the result to the real image. If the cache no longer matches the file, the crop box lies outside the image and the backend throws (vips:extract_area: bad extract area), so the page fails to render.This is easy to hit with the image editor added in silverstripe/asset-admin 3.3 (CMS 6.3). It crops, rotates or flips an existing image in place, so the file's dimensions change. If the cached size is not refreshed, every
FocusFill*()call on that image fails. The cause on the assets side is that theFilekeeps its cached image backend after the asset is replaced, sogetWidth()/getHeight()return the old size and FocusPoint'sonBeforeWrite()stores it again. That is reported in silverstripe/silverstripe-assets#724 and fixed in silverstripe/silverstripe-assets#725.This PR makes FocusPoint safe regardless of how the cache went stale (other modules, external file replacement, DB copies, or an unfixed assets version).
Change
applyCrop(): if the backend size differs from the cached size, fall back to a centeredcroppedResize()instead of an out-of-bounds crop. Nothing is written to the DB, so it is safe on read paths.getX()/getY(): clamp to [-1, 1]. The setters already do, but values hydrated from the DB did not.The focus point is not remapped after an edit. That can't be done reliably from inside this module, so the fallback centers the crop until the dimensions are refreshed.
Tests
Added a clamp test and a stale-dimensions regression test, which fails with
bad extract areawithout this change.testFocusFillandtestFocusFillMaxalready fail on Intervention Image 4 becausepickColor()no longer exists. That is unrelated to this PR.