From 50060bf928c8372e816eb5e69f144818c69edb08 Mon Sep 17 00:00:00 2001 From: MrYamous Date: Sat, 4 Apr 2026 07:20:46 +0200 Subject: [PATCH] [Cropper] Always apply rotation in `Crop::getCroppedImage()` and `Crop::getCroppedThumbnail()` --- src/Cropperjs/CHANGELOG.md | 1 + src/Cropperjs/src/Model/Crop.php | 14 ++++---------- src/Cropperjs/tests/Model/CropTest.php | 8 ++++---- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/Cropperjs/CHANGELOG.md b/src/Cropperjs/CHANGELOG.md index 16b5817bdd4..2cb2f14e149 100644 --- a/src/Cropperjs/CHANGELOG.md +++ b/src/Cropperjs/CHANGELOG.md @@ -4,6 +4,7 @@ - Minimum required Symfony version is now 6.4 - Minimum required PHP version is now 8.2 +- Always apply rotation in `Crop::getCroppedImage()` and `Crop::getCroppedThumbnail()` ## 2.34 diff --git a/src/Cropperjs/src/Model/Crop.php b/src/Cropperjs/src/Model/Crop.php index 4052658873d..74fc8d2c3da 100644 --- a/src/Cropperjs/src/Model/Crop.php +++ b/src/Cropperjs/src/Model/Crop.php @@ -55,11 +55,8 @@ public function __construct(ImageManager $imageManager, string $filename) $this->filename = $filename; } - public function getCroppedThumbnail(int $maxWidth, int $maxHeight, string $format = 'jpg', int $quality = 80, bool $applyRotation = false): string + public function getCroppedThumbnail(int $maxWidth, int $maxHeight, string $format = 'jpg', int $quality = 80): string { - if (\func_num_args() < 5 || false === $applyRotation) { - trigger_deprecation('symfony/ux-cropperjs', '2.34', 'Not passing "true" to the "$applyRotation" argument of "%s()" is deprecated. Rotation will be applied by default in Symfony UX 3.0.', __METHOD__); - } $image = $this->createCroppedImage(); $image->resize($maxWidth, $maxHeight, static function ($constraint) { @@ -67,7 +64,7 @@ public function getCroppedThumbnail(int $maxWidth, int $maxHeight, string $forma $constraint->upsize(); }); - if ($applyRotation && !empty($this->options['rotate'])) { + if (!empty($this->options['rotate'])) { $image->rotate(-1 * $this->options['rotate']); } @@ -76,11 +73,8 @@ public function getCroppedThumbnail(int $maxWidth, int $maxHeight, string $forma return $image->getEncoded(); } - public function getCroppedImage(string $format = 'jpg', int $quality = 80, bool $applyRotation = false): string + public function getCroppedImage(string $format = 'jpg', int $quality = 80): string { - if (\func_num_args() < 3 || false === $applyRotation) { - trigger_deprecation('symfony/ux-cropperjs', '2.34', 'Not passing "true" to the "$applyRotation" argument of "%s()" is deprecated. Rotation will be applied by default in Symfony UX 3.0.', __METHOD__); - } $image = $this->createCroppedImage(); // Max size @@ -91,7 +85,7 @@ public function getCroppedImage(string $format = 'jpg', int $quality = 80, bool }); } - if ($applyRotation && !empty($this->options['rotate'])) { + if (!empty($this->options['rotate'])) { $image->rotate(-1 * $this->options['rotate']); } diff --git a/src/Cropperjs/tests/Model/CropTest.php b/src/Cropperjs/tests/Model/CropTest.php index c819c877751..06bb2104a77 100644 --- a/src/Cropperjs/tests/Model/CropTest.php +++ b/src/Cropperjs/tests/Model/CropTest.php @@ -55,7 +55,7 @@ public function testGetCroppedImageWithRotation() { $crop = $this->createCrop(rotate: 90); - $result = $crop->getCroppedImage(applyRotation: true); + $result = $crop->getCroppedImage(); $image = imagecreatefromstring($result); $this->assertSame(100, imagesx($image)); @@ -66,7 +66,7 @@ public function testGetCroppedImageWithoutRotation() { $crop = $this->createCrop(rotate: 0); - $result = $crop->getCroppedImage(applyRotation: true); + $result = $crop->getCroppedImage(); $image = imagecreatefromstring($result); $this->assertSame(200, imagesx($image)); @@ -77,7 +77,7 @@ public function testGetCroppedThumbnailWithRotation() { $crop = $this->createCrop(rotate: 90); - $result = $crop->getCroppedThumbnail(200, 200, applyRotation: true); + $result = $crop->getCroppedThumbnail(200, 200); $image = imagecreatefromstring($result); $this->assertSame(100, imagesx($image)); @@ -88,7 +88,7 @@ public function testGetCroppedThumbnailWithoutRotation() { $crop = $this->createCrop(rotate: 0); - $result = $crop->getCroppedThumbnail(200, 200, applyRotation: true); + $result = $crop->getCroppedThumbnail(200, 200); $image = imagecreatefromstring($result); $this->assertSame(200, imagesx($image));