Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Cropperjs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 4 additions & 10 deletions src/Cropperjs/src/Model/Crop.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,16 @@ 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) {
$constraint->aspectRatio();
$constraint->upsize();
});

if ($applyRotation && !empty($this->options['rotate'])) {
if (!empty($this->options['rotate'])) {
$image->rotate(-1 * $this->options['rotate']);
}

Expand All @@ -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
Expand All @@ -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']);
}

Expand Down
8 changes: 4 additions & 4 deletions src/Cropperjs/tests/Model/CropTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -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));
Expand Down
Loading