Add automatic saliency cropping - #46
Conversation
Greptile SummaryThis PR adds saliency-aware automatic cropping (
Confidence Score: 3/5
Important Files Changed
Reviews (5): Last reviewed commit: "Merge main into feat/semantic-focus-crop" | Re-trigger Greptile |
| { | ||
| self::$focusDetector ??= pipeline('zero-shot-object-detection'); | ||
|
|
||
| $path = tempnam(sys_get_temp_dir(), 'utopia-image-focus-'); |
There was a problem hiding this comment.
tempnam prefix truncated on Windows
The prefix 'utopia-image-focus-' is 19 characters. PHP's tempnam() documentation states that on Windows only the first 3 characters of the prefix are used, so the created file gets the prefix uto instead. Keeping the prefix at 5 characters or fewer would work reliably on all platforms.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Image/Image.php
Line: 273
Comment:
**`tempnam` prefix truncated on Windows**
The prefix `'utopia-image-focus-'` is 19 characters. PHP's `tempnam()` documentation states that on Windows only the first 3 characters of the prefix are used, so the created file gets the prefix `uto` instead. Keeping the prefix at 5 characters or fewer would work reliably on all platforms.
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Summary
Image::GRAVITY_AUTOfor saliency-aware croppingankane/onnxruntimeImage::detect()so model inference can run in a dedicated workercrop()to consume a persisted detection result without loading ONNXUsage
The detection result contains
width,height, and a normalized two-dimensionalmask.Model and runtime
8d10d2f3bb75ae3b6d527c77944fc5e7dcd94b29809d47a739a7a728a912b491resources/models/NOTICE.mdOnnxRuntime\Vendor::checkto root Composer post-install and post-update scriptsPerformance
Measured on an Apple M3 Pro with a 1280x837 JPEG cropped to 180x320:
Native ONNX Runtime and Imagick allocations are not fully represented by PHP's memory counter. Automatic detection is best suited to an asynchronous, controlled-concurrency worker.
Testing
vendor/bin/pint --test