Support configurable and auto-detected output format for cropped images#34
Support configurable and auto-detected output format for cropped images#34paodb wants to merge 2 commits into
Conversation
|
Warning Review limit reached
Next review available in: 47 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (7)
WalkthroughAdds configurable cropped-image output MIME type and quality, with client-side format detection, circular-crop PNG fallback, a new demo, unit tests, README updates, and a version bump. ChangesOutput format configuration
Estimated code review effort: 2 (Simple) | ~15 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
src/test/java/com/flowingcode/vaadin/addons/imagecrop/test/ImageCropTest.java (1)
48-61: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider adding tests for default (auto-detect) state.
These tests only verify explicit set/get round-trips. The PR's headline feature is auto-detection when
outputMimeType/outputQualityare left unset (null). Consider adding a test assertinggetOutputMimeType()returnsnullby default (before anysetOutputMimeTypecall) to lock in the auto-detect contract.✅ Suggested additional test
+ `@Test` + public void testGetOutputMimeTypeDefaultsToNull() { + assertNull(imageCrop.getOutputMimeType()); + }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/test/java/com/flowingcode/vaadin/addons/imagecrop/test/ImageCropTest.java` around lines 48 - 61, Add a test in ImageCropTest that exercises the default auto-detect state before any setters are called: verify imageCrop.getOutputMimeType() returns null initially, and if applicable do the same for outputQuality. Use the existing ImageCrop test fixture and the getOutputMimeType()/getOutputQuality() accessors to lock in the unset/null contract, instead of only testing set/get round-trips.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/main/java/com/flowingcode/vaadin/addons/imagecrop/ImageCrop.java`:
- Around line 143-154: The refreshCroppedImage() flow currently depends on
setState(...) having already been applied before
getElement().executeJs("_updateCroppedImage(...)") runs, which is not guaranteed
by Vaadin. Update the ImageCrop logic so the re-encode uses client-side state
consistently, either by moving the update into a client-side effect or by
passing the new crop/mime/quality values directly from the caller into
refreshCroppedImage()/_updateCroppedImage(). Ensure the fix is applied where
property-change handlers trigger refreshCroppedImage() so the client always uses
the intended latest values.
- Around line 378-398: `ImageCrop#getOutputQuality()` can still fail if the
server-side state has never been initialized, even though the client defaults to
1.0. Update `ImageCrop` to initialize `outputQuality` on the Java side
(preferably in the constructor) or make `getOutputQuality()` fall back to 1.0
when the state is absent, and keep the existing `setOutputQuality` /
`refreshCroppedImage` flow unchanged.
In `@src/main/resources/META-INF/resources/frontend/src/image-crop.tsx`:
- Around line 300-302: The server-side output quality path can unbox a null
primitive before the client initializes its fallback value, so mirror the
client’s 1.0 default there. Update the relevant server-side getter or
initializer for output quality so it safely falls back to 1.0 when the nullable
state is unset, keeping behavior aligned with the frontend’s `this.outputQuality
?? 1.0` in `image-crop.tsx`.
---
Nitpick comments:
In
`@src/test/java/com/flowingcode/vaadin/addons/imagecrop/test/ImageCropTest.java`:
- Around line 48-61: Add a test in ImageCropTest that exercises the default
auto-detect state before any setters are called: verify
imageCrop.getOutputMimeType() returns null initially, and if applicable do the
same for outputQuality. Use the existing ImageCrop test fixture and the
getOutputMimeType()/getOutputQuality() accessors to lock in the unset/null
contract, instead of only testing set/get round-trips.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 50c61048-98f9-49a4-bbb3-29d5cccd1bbb
📒 Files selected for processing (7)
README.mdpom.xmlsrc/main/java/com/flowingcode/vaadin/addons/imagecrop/ImageCrop.javasrc/main/resources/META-INF/resources/frontend/src/image-crop.tsxsrc/test/java/com/flowingcode/vaadin/addons/imagecrop/ImageCropDemoView.javasrc/test/java/com/flowingcode/vaadin/addons/imagecrop/OutputFormatImageCropDemo.javasrc/test/java/com/flowingcode/vaadin/addons/imagecrop/test/ImageCropTest.java
63bd5fa to
3545968
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/java/com/flowingcode/vaadin/addons/imagecrop/ImageCrop.java (1)
387-389: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider validating
outputQualitybounds.
setOutputQualityaccepts anydoublewith no range check, though the Javadoc states "a value between 0 and 1". Out-of-range values are silently passed through tocanvas.toDataURLon the client.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/main/java/com/flowingcode/vaadin/addons/imagecrop/ImageCrop.java` around lines 387 - 389, `ImageCrop.setOutputQuality` currently passes any double through without enforcing the documented 0-to-1 range. Add validation in this setter to reject or clamp out-of-bounds values before calling `setState("outputQuality", ...)`, so the method matches its Javadoc and only sends valid quality values to the client.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/main/java/com/flowingcode/vaadin/addons/imagecrop/ImageCrop.java`:
- Around line 387-389: `ImageCrop.setOutputQuality` currently passes any double
through without enforcing the documented 0-to-1 range. Add validation in this
setter to reject or clamp out-of-bounds values before calling
`setState("outputQuality", ...)`, so the method matches its Javadoc and only
sends valid quality values to the client.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: b6eb90f1-5355-405a-b6a3-23064cb9a113
📒 Files selected for processing (7)
README.mdpom.xmlsrc/main/java/com/flowingcode/vaadin/addons/imagecrop/ImageCrop.javasrc/main/resources/META-INF/resources/frontend/src/image-crop.tsxsrc/test/java/com/flowingcode/vaadin/addons/imagecrop/ImageCropDemoView.javasrc/test/java/com/flowingcode/vaadin/addons/imagecrop/OutputFormatImageCropDemo.javasrc/test/java/com/flowingcode/vaadin/addons/imagecrop/test/ImageCropTest.java
✅ Files skipped from review due to trivial changes (2)
- pom.xml
- README.md
🚧 Files skipped from review as they are similar to previous changes (3)
- src/test/java/com/flowingcode/vaadin/addons/imagecrop/ImageCropDemoView.java
- src/test/java/com/flowingcode/vaadin/addons/imagecrop/OutputFormatImageCropDemo.java
- src/main/resources/META-INF/resources/frontend/src/image-crop.tsx
3545968 to
9f06011
Compare
|



Reworks the fix for #23 following the approach agreed in the PR #27 discussion: a combination of an explicit server-side output-format property and zero-network auto-detection. Supersedes #27.
Problem
The cropped image was always encoded as PNG (
canvas.toDataURL("image/png", ...)), so JPEGs (and any other format) were silently converted to PNG.What this does
setOutputMimeType(String)lets the caller choose the output format (image/png,image/jpeg,image/webp).data:URI, or the file extension of a regular URL.canvas.toDataURLcan actually encode (png/jpeg/webp); anything else falls back toimage/png.setOutputQuality(double)controls the encoding quality for lossy formats (jpeg/webp).Notes
Closes #23
Summary by CodeRabbit