#61514 closed defect (bug) (fixed)
Media attachments REST API endpoint: Fix cropping on one axis only
Reported by: | andrewserong | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 6.6 | Priority: | normal |
Severity: | normal | Version: | 6.6 |
Component: | REST API | Keywords: | has-patch has-unit-tests |
Focuses: | Cc: |
Description
As discussed in #59782, a fix for casting values as int in the attachments REST API endpoint revealed a bug in the endpoint for image cropping where if requesting a crop on only one axis, the crop would fail to take effect.
A proposed solution is to update the logic in the endpoint so that a crop is valid if at least one dimension of the target image size is different from the source image size, rather than requiring both dimensions to be different.
To reproduce the issue, see the reproduction steps in https://github.com/WordPress/gutenberg/issues/62855 — in the block editor, in 6.6 RC 1, cropping the image block fails because the block editor uses an aspect-ratio based crop where one dimension is always the same as the source image.
Change History (12)
This ticket was mentioned in PR #6909 on WordPress/wordpress-develop by @andrewserong.
7 months ago
#1
- Keywords has-patch has-unit-tests added
@andrewserong commented on PR #6909:
7 months ago
#2
Thanks for the feedback @jrfnl! I've added a unit test, copying the existing one for image cropping, but updating it to include cropping on only one axis.
@andrewserong commented on PR #6909:
7 months ago
#3
@jrfnl or @joedolson this PR is ready for another review and commit if it's all looking okay. It'd be great to get this fix in for the next 6.6 RC if we can.
@SergeyBiryukov commented on PR #6909:
7 months ago
#6
Thanks for the PR! Merged in r58612.
#7
@
7 months ago
- Keywords dev-feedback added
- Resolution fixed deleted
- Status changed from closed to reopened
Reopening for backporting to the 6.6 branch after a second committer's review.
#8
@
7 months ago
- Keywords dev-reviewed added; dev-feedback removed
@andrewserong Sorry this didn't get picked up in time for RC2. This can go into RC3 though. Signing off so it can be backported to the 6.6 branch.
## What
Fixes cropping tools in the block editor. Related Gutenberg issue: https://github.com/WordPress/gutenberg/issues/62855.
## Why
Currently, the cropping tool in the block editor doesn't apply the selected crop.
As of https://github.com/WordPress/wordpress-develop/commit/4f175e167ebd33d68ebe347fcc376f1342d9e873 / https://github.com/WordPress/wordpress-develop/pull/6876, the width and height cropping values are rounded and cast to an
int
before the comparison to see if the target width and height differ from the original width and height.Since they are now
int
s, it exposes a bug where the&&
of theif
conditional meant that if you were only cropping in one dimension, the check wouldn't pass, and cropping would not occur.In the block editor, the cropping tools are aspect ratio based, so one of the dimensions will always match that of the source image. Therefore, now that the values are cast as
int
s, we need to update the condition that allows a cropping to occur. In this case, I believe it should be||
instead of&&
. If either width or height is different from the source image, then we should allow a crop.## How to test
Trac ticket: https://core.trac.wordpress.org/ticket/61514