[3.x] Add edge image editor saves#168
Conversation
7ca1d8b to
19827b5
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 19827b5f8d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if ($imageRotated) { | ||
| $behavior->rotate = $rotation; | ||
|
|
There was a problem hiding this comment.
Reject unsupported arbitrary rotations
When the editor sends a non-right-angle imageRotation such as 135° (the new test covers this path), this assigns rotate=135 to the Cloudflare transform URL. Cloudflare's transform docs for rotate only accept 90, 180, or 270, so saving those edits will fail during downloadEditedImage() instead of producing the rotated asset: https://developers.cloudflare.com/images/transform-images/transform-via-url/#rotate. This needs to either fall back to Craft/PHP image processing or avoid handling unsupported rotations.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Pull request overview
Adds a Craft Cloud image-editor save handler that converts Craft’s image editor state (crop/rotate/flip/zoom + focal point) into Cloudflare image transform options, allowing edited images to be saved/replaced without doing server-side image decoding.
Changes:
- Register an asset-image save event handler and implement a new
ImageEditorclass that downloads the transformed image and saves/replaces the asset. - Add
ImageTransformer::fromImageEditor()to map editor state into a CloudImageTransform+ Cloudflare options. - Expand Cloudflare option output to include
quality, and add unit tests covering quality + editor mappings.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/ImageTransformTest.php | Adds unit tests for quality mapping and image-editor state → Cloudflare option mapping. |
| src/Module.php | Hooks Craft’s “before save image” event to the new Cloud image editor save handler when Asset CDN is enabled. |
| src/imagetransforms/ImageTransformer.php | Adds fromImageEditor() to build a Cloud image transform from editor crop/rotate/flip/zoom. |
| src/imagetransforms/ImageTransformBehavior.php | Updates Cloudflare docs link and includes quality in generated Cloudflare options. |
| src/imagetransforms/ImageEditor.php | New handler to intercept image-editor saves, compute focal point/transform, and replace or create assets by downloading Cloudflare-transformed output. |
| composer.json | Tightens supported Craft CMS versions to those exposing the image-editor save event. |
| composer.lock | Updates dependency lockfile (including Craft CMS and transitive packages). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| use craft\cloud\Module as CloudModule; | ||
| use craft\cloud\fs\AssetsFs; | ||
| use craft\cloud\imagetransforms\ImageEditor; | ||
| use craft\cloud\imagetransforms\ImageTransformBehavior; | ||
| use craft\cloud\imagetransforms\ImageTransformer; | ||
| use craft\elements\Asset; |
2727e91 to
3d2a075
Compare
3d2a075 to
2b63be8
Compare
Description
Adds a Cloud image-editor save handler that maps Craft editor state to Cloudflare image transform options, then saves or replaces the asset without PHP image decoding.
Requires Craft CMS versions that expose the image-editor save event and expands Cloudflare option support for the editor transform path.