Repository navigation
Conversation
|
Size Change: +980 B (+0.01%) Total Size: 7.92 MB 📦 View Changed
|
ramonjd
commented
Jun 22, 2026
ramonjd
force-pushed
the
ramonjd/circle-crop-stencil
branch
from
June 22, 2026 07:29
3486e5e to
a63aeb2
Compare
ramonjd
commented
Jun 22, 2026
ramonjd
force-pushed
the
ramonjd/circle-crop-stencil
branch
2 times, most recently
from
June 23, 2026 06:46
509d976 to
236386f
Compare
ramonjd
commented
Jun 23, 2026
|
Flaky tests detected in fc44ae3. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/29396064709
|
ramonjd
force-pushed
the
ramonjd/circle-crop-stencil
branch
2 times, most recently
from
June 26, 2026 03:54
21c22f7 to
792717d
Compare
ramonjd
commented
Jun 26, 2026
65 of 77 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
Adds MVP/POC support for circular image crops in the Media Editor, spanning UI/state updates in packages/media-editor and a WordPress REST /edit compatibility layer that can apply a circular mask and output PNG to preserve transparency.
Changes:
- Introduces a
cropShapeoption (rectangle/circle) with undo/history integration and “dirty” tracking. - Adds a circular stencil UI (edge handles + circular overlay styling) and exposes shape selection in the Crop panel and mobile/toolbar controls.
- Extends the attachments
/editflow with an experimentalmaskmodifier and registers mask-capable image editors (Imagick/GD) to produce circular PNG outputs.
Reviewed changes
Copilot reviewed 33 out of 33 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/media-editor/src/state/use-media-editor-state.ts | Adds setCropShape controller API and includes crop shape in dirty tracking. |
| packages/media-editor/src/state/types.ts | Defines CropShape and adds cropShape to CropOptionsSlice + action types. |
| packages/media-editor/src/state/test/use-media-editor-state.ts | Adds coverage for undo/dirty behavior when switching crop shape. |
| packages/media-editor/src/state/index.ts | Re-exports CropShape type. |
| packages/media-editor/src/state/composite-reducer.ts | Implements SET_CROP_SHAPE handling and includes crop shape in equality checks. |
| packages/media-editor/src/image-editor/react/components/stencils/test/circle-stencil.tsx | Adds unit test ensuring circle stencil uses edge handles (not corners). |
| packages/media-editor/src/image-editor/react/components/stencils/rectangle-stencil.tsx | Adds internal props to support circle styling and edge-handle locking. |
| packages/media-editor/src/image-editor/react/components/stencils/circle-stencil.tsx | Implements circle stencil by composing RectangleStencil with square constraints. |
| packages/media-editor/src/image-editor/react/components/index.ts | Exports CircleStencil. |
| packages/media-editor/src/image-editor/react/components/cropper.tsx | Adds stencilShape support and enforces square constraints for circle crops. |
| packages/media-editor/src/image-editor/react/components/cropper.scss | Adds circular overlay styling (grid/dimming/stencil border radius). |
| packages/media-editor/src/image-editor/index.ts | Re-exports CircleStencil from the package surface. |
| packages/media-editor/src/image-editor/core/test/stencil-math.ts | Adds test coverage for locked edge-handle resizing behavior. |
| packages/media-editor/src/image-editor/core/stencil-math.ts | Adds computeLockedEdgeResizeRect and routes edge handles through it. |
| packages/media-editor/src/components/media-editor/use-save-media-editor.ts | Appends mask modifier when cropShape is circle. |
| packages/media-editor/src/components/media-editor/use-crop-options.ts | Exposes cropShape setters and resolves circle to a square aspect ratio. |
| packages/media-editor/src/components/media-editor/test/use-crop-options.tsx | Adds coverage for circle resolved aspect ratio and reset behavior. |
| packages/media-editor/src/components/media-editor/style.scss | Tweaks sidebar padding on small breakpoints. |
| packages/media-editor/src/components/media-editor/index.tsx | Wires crop shape into Crop panel and hides aspect ratio controls for circles. |
| packages/media-editor/src/components/media-editor-modal/build-modifiers.ts | Extends modifier union type to include mask. |
| packages/media-editor/src/components/media-editor-image-controls/test/index.tsx | Adds test coverage for toolbar crop-shape dropdown and circle behavior. |
| packages/media-editor/src/components/media-editor-image-controls/style.scss | Adjusts toolbar layout wrapping/centering for added controls. |
| packages/media-editor/src/components/media-editor-image-controls/index.tsx | Adds crop-shape dropdown and hides aspect ratio dropdown for circle crops. |
| packages/media-editor/src/components/media-editor-crop-panel/test/index.tsx | Adds test coverage for crop shape selection and circle-specific UI behavior. |
| packages/media-editor/src/components/media-editor-crop-panel/index.tsx | Adds shape toggle group and conditionally renders aspect ratio selector. |
| packages/media-editor/src/components/media-editor-canvas/index.tsx | Passes circle stencil + stencilShape to the Cropper when shape is circle. |
| lib/media/class-gutenberg-rest-attachments-controller.php | Switches controller base to a mask-capable attachments controller. |
| lib/compat/wordpress-7.1/image-editor-mask.php | Registers mask-capable Gutenberg image editors via wp_image_editors filter. |
| lib/compat/wordpress-7.1/image-editor-mask-validation.php | Adds validation/normalization helper for mask arguments. |
| lib/compat/wordpress-7.1/class-gutenberg-rest-attachments-controller-with-mask.php | Adds mask modifier schema and custom /edit flow to apply mask + PNG output. |
| lib/compat/wordpress-7.1/class-gutenberg-rest-attachments-controller-7-1.php | Updates 7.1 controller to inherit mask-capable base. |
| lib/compat/wordpress-7.1/class-gutenberg-image-editor-imagick.php | Adds Imagick editor subclass implementing mask() for circle cropping. |
| lib/compat/wordpress-7.1/class-gutenberg-image-editor-gd.php | Adds GD editor subclass implementing mask() for circle cropping. |
ramonjd
force-pushed
the
ramonjd/circle-crop-stencil
branch
from
June 30, 2026 04:52
2c159e3 to
c8cd436
Compare
Comment on lines
+327
to
+335
| // A circle crop introduces transparency, so the new attachment must be | ||
| // saved as a PNG. | ||
| const [ | ||
| { | ||
| attributes: { url }, | ||
| }, | ||
| ] = await editor.getBlocks(); | ||
| expect( url ).toMatch( /\.png$/ ); | ||
| await expect( image ).toHaveAttribute( 'src', /\.png$/ ); |
ramonjd
force-pushed
the
ramonjd/circle-crop-stencil
branch
from
July 15, 2026 06:48
915a538 to
93700bd
Compare
6 tasks done
ramonjd
force-pushed
the
ramonjd/circle-crop-stencil
branch
from
July 30, 2026 06:41
fc44ae3 to
c221dba
Compare
- Scope the mask image-editor filter to the edit request instead of swapping the global editor site-wide; load its helper from load.php. - Remove the dead legacy-modifier branch and inline the circle-mask request check. - Use a scanline fill for the GD circle mask (O(height) instead of O(width*height) per-pixel writes). - Return a status array from the Imagick mask error. - Let Cropper own the circle 1:1 ratio; drop the redundant canvas branch. - Clarify the circle crop help text. - Add PHP tests for mask validation, edit schema, GD masking, and the mask/non-mask edit routing.
Instead of unconditionally forcing PNG, honor the site's image_editor_output_format choice when it can hold an alpha channel (WebP/AVIF) and fall back to PNG otherwise. The format is forced for the save so a site filter cannot remap it back to an opaque format and discard the mask. - Move the format decision out of the editor mask() methods, which now mutate pixels only like the other transforms. - Drop the redundant Imagick setImageFormat and its test() gate entry. - Add a test covering the alpha-capable (WebP) negotiation path.
Backend: - Document the edit_media_item() fork (pinned to WordPress 7.1) and why copying is required to extend Core's closed modifier loop. - Drop the redundant per-branch schema type to match Core's flip/rotate/ crop modifiers; document that masks apply after geometry modifiers and force that order regardless of request position. - Guard the PNG output fallback against an editor that cannot write the negotiated format. UI: - Disable (grey out) the aspect-ratio controls for circle crops instead of hiding them, in both the sidebar panel and the mobile footer toolbar. Tests/docs: - Add an e2e test for saving a circle crop as a transparent PNG. - Add a PHP test that a site mapping an alpha format to an opaque one still yields an alpha-capable masked output. - Add a media-editor CHANGELOG entry.
Bring the Gutenberg controller and GD editor in line with the Core backport (wordpress-develop#12327) so the fork tracks Core: - Request the editor with `output_mime_type => image/png`. - Distinguish `image_no_editor` (mask unsupported) from other editor failures. - Force the output-format suppression at `PHP_INT_MAX` and set the new attachment guid from `$saved['file']`. - Restore the `type => object` schema key on the mask modifier. - Gate GD mask support on `supports_mime_type( 'image/png' )`. The feature lands in Core 7.2, so move the mask compat files to `lib/compat/wordpress-7.2/`, update the require paths, and add the backport changelog entry.
ramonjd
force-pushed
the
ramonjd/circle-crop-stencil
branch
from
August 31, 2026 02:45
c221dba to
d2cd0aa
Compare
PHP 8.5 deprecates ReflectionMethod::setAccessible() (a no-op since 8.1) and imagedestroy() (a no-op since 8.0), which the WordPress test suite promotes to test errors. Only call setAccessible() below PHP 8.1, where invoking the protected method still requires it. Drop the imagedestroy() calls outright: the image is freed when the variable goes out of scope on every supported PHP version.
The media-editor package no longer uses the External/WordPress/Internal dependency comment convention, and lint:js now rejects the comment blocks and the blank lines between import groups.
Unit test environments are now enforced by filename (#80991): only *.jsdom.test.* files run under jsdom, and the circle stencil test renders with Testing Library, so under the default node environment it failed with 'document is not defined'. Matches the neighbouring rectangle-stencil.jsdom.test.tsx.
2 of 18 tasks
This branch has not been deployed
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.
What?
Adds MVP support for circular crops in the media editor. At the moment its state is MVP/POC to guide direction.
Kapture.2026-06-26.at.14.26.45.mp4
Backport PR here: WordPress/wordpress-develop#12327
Testing Instructions
Known behavior & follow-ups
image_editor_output_formatmapping is honored when it can hold transparency (WebP/AVIF); otherwise the output falls back to PNG. JPEG/GIF sources and the default HEIC/HEIF → JPEG mapping therefore produce PNG.maskmodifier is implemented by forking Core'sWP_REST_Attachments_Controller::edit_media_item(), because Core's modifier loop has no hook to inject a new modifier type. The intended end state is a first-classmask()operation onWP_Image_Editorplus acase 'mask'in Core's edit pipeline, after which this fork is removed.