[Cropperjs] Upgrade to Intervention Image v4 and make the image driver configurable#3679
[Cropperjs] Upgrade to Intervention Image v4 and make the image driver configurable#3679deluxetom wants to merge 3 commits into
Conversation
d756cf4 to
c5a7ee9
Compare
…r configurable Migrate the server-side cropping from intervention/image ^2.5 (v2) to ^4.0, which removes the indirect v2 deprecations reported in symfony#3394. The Crop model now uses the v4 API (decodeBinary/scaleDown/encodeUsingFileExtension and ImageManagerInterface). Add a configurable image driver through a new bundle configuration: * cropperjs.driver: gd (default), imagick or vips * cropperjs.driver_service: a custom Intervention DriverInterface service, which takes precedence over driver The ImageManager is built via ImageManager::usingDriver(); selecting vips without the intervention/image-driver-vips package fails fast with a helpful message. GD remains the zero-config default, preserving current behavior. Tests are parameterized over the gd and imagick drivers and now cover the crop region, max-size downscaling and output format paths.
c5a7ee9 to
9d5a7e3
Compare
|
|
||
| if (!empty($this->options['rotate'])) { | ||
| $image->rotate(-1 * $this->options['rotate']); | ||
| $image->rotate(-1 * $this->options['rotate'], 'ffffff'); |
There was a problem hiding this comment.
In V4 the rotate() rotates clockwise by default (from upgrade guide), i'm not sure the -1 is still appropriated with this change. Tests are done with a 90 degrees rotation so I don't think it's noticeable. Maybe we need to add a new test for that ?
There was a problem hiding this comment.
Verified: in v2 rotate() turned counter-clockwise for positive angles, so the -1 * matched cropper.js (which rotates clockwise for positive degrees). In v4 rotate() turns clockwise for positive angles (RotateModifier docblock says "Clockwise rotation angle", and the GD modifier negates internally for imagerotate), so the negation now inverts the output relative to the cropper preview.
Dropped the -1 and added a directional test (testGetCroppedImageRotatesClockwise): a left-red/right-blue image rotated 90° should land red on top and blue on the bottom. The existing 90° tests only asserted dimensions, which are direction-agnostic, so they couldn't catch this. Fixed in 72f9563.
In v2 rotate() turned counter-clockwise for positive angles, so the crop applied -1 * rotate to match cropper.js (clockwise positive). In v4 rotate() turns clockwise for positive angles, so the negation now inverts the output relative to the cropper preview. Pass the angle directly and add a directional test (the existing 90° tests only asserted dimensions, which are direction-agnostic). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
v4's Config::$backgroundColor already defaults to 'ffffff', and rotate(angle, null) falls back to it, so passing 'ffffff' explicitly is redundant. Omitting it keeps the same white-corner output while letting a custom driver_service ImageManager control the fill via its own config. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Resolves the indirect
intervention/imagev2 deprecations reported in #3394 by upgrading the dependency to v4, and adds the ability to choose the image driver (proposal/discussion in #3678).What changes
intervention/image:^2.5→^4.0(drops v2). TheCropmodel migrates to the v4 API:make()→decodeBinary(), theresize(closure)aspect-ratio + upsize calls →scaleDown(),encode()+getEncoded()→encodeUsingFileExtension(), and the type-hints move toImageManagerInterface/ImageInterface.The
ImageManageris built throughImageManager::usingDriver().gd/imagickare bundled withintervention/image;vipsuses the officialintervention/image-driver-vipspackage, declared under composersuggest(it needs libvips +ext-ffi). Selectingvipswithout that package fails fast at container compile time with an actionable message.driver_servicelets advanced users inject a fully custom / pre-configuredDriverInterface.Backward compatibility
The bundle's public API is unchanged and
gdremains the zero-config default, so existing apps behave exactly as before. The only requirement change isintervention/imagev4 (PHP >= 8.3, already satisfied by the bundle's PHP >= 8.4 floor).Tests
CropTestis parameterized over the gd and imagick drivers and now covers the crop region (locking thecrop()argument order),setCroppedMaxSize()downscaling, thumbnail downscaling and output format. NewConfigurationTestandCropperjsExtensionTestcover the driver configuration, the custom-driver precedence and the fail-fastvipsguard.