From 31d421c388338793a4e92d86122658fe8c364e29 Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 22 Jan 2024 12:10:20 +0100 Subject: [PATCH 01/64] define missing properties in tests --- tests/Api/ApiTest.php | 2 +- tests/Manipulators/CropTest.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Api/ApiTest.php b/tests/Api/ApiTest.php index 8320e423..8e22d0ee 100644 --- a/tests/Api/ApiTest.php +++ b/tests/Api/ApiTest.php @@ -8,7 +8,7 @@ class ApiTest extends TestCase { - private $output; + private $api; public function setUp(): void { diff --git a/tests/Manipulators/CropTest.php b/tests/Manipulators/CropTest.php index 98c4d570..05ff0de8 100644 --- a/tests/Manipulators/CropTest.php +++ b/tests/Manipulators/CropTest.php @@ -8,6 +8,7 @@ class CropTest extends TestCase { private $manipulator; + private $image; public function setUp(): void { From bf55901a266df1d01975dd7d3ad2a94840f3d239 Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 22 Jan 2024 12:10:53 +0100 Subject: [PATCH 02/64] bump php requiremet to 8.1 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 57b646bc..1c176ff7 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ } ], "require": { - "php": "^7.2|^8.0", + "php": "^8.1", "intervention/image": "^2.7", "league/flysystem": "^2.0|^3.0", "psr/http-message": "^1.0|^2.0" From 47fa74711a59e37cc255e5e6dd7a11043ec0a987 Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 22 Jan 2024 12:12:22 +0100 Subject: [PATCH 03/64] update to intervention/glide v3 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 1c176ff7..e2f7ea59 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ ], "require": { "php": "^8.1", - "intervention/image": "^2.7", + "intervention/image": "^3", "league/flysystem": "^2.0|^3.0", "psr/http-message": "^1.0|^2.0" }, From 3105fa6424d5072294bda844b02af846d19ef562 Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 22 Jan 2024 12:56:07 +0100 Subject: [PATCH 04/64] Update ServerFactory --- src/ServerFactory.php | 14 +++++++++++--- tests/ServerFactoryTest.php | 14 +++++++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/ServerFactory.php b/src/ServerFactory.php index 3dbf987c..8a925b1d 100644 --- a/src/ServerFactory.php +++ b/src/ServerFactory.php @@ -2,6 +2,8 @@ namespace League\Glide; +use Intervention\Image\Drivers\Gd\Driver as GdDriver; +use Intervention\Image\Drivers\Imagick\Driver as ImagickDriver; use Intervention\Image\ImageManager; use InvalidArgumentException; use League\Flysystem\Filesystem; @@ -246,9 +248,15 @@ public function getImageManager() $driver = $this->config['driver']; } - return new ImageManager([ - 'driver' => $driver, - ]); + if ($driver === 'gd') { + $manager = ImageManager::gd(); + } else if ($driver === 'imagick') { + $manager = ImageManager::imagick(); + } else { + $manager = ImageManager::withDriver($driver); + } + + return $manager; } /** diff --git a/tests/ServerFactoryTest.php b/tests/ServerFactoryTest.php index 8d71f547..0ed1570a 100644 --- a/tests/ServerFactoryTest.php +++ b/tests/ServerFactoryTest.php @@ -156,7 +156,7 @@ public function testGetApi() $this->assertInstanceOf('League\Glide\Api\Api', $server->getApi()); } - public function testGetImageManager() + public function testGetImageManagerWithImagick() { $server = new ServerFactory([ 'driver' => 'imagick', @@ -164,7 +164,16 @@ public function testGetImageManager() $imageManager = $server->getImageManager(); $this->assertInstanceOf('Intervention\Image\ImageManager', $imageManager); - $this->assertSame('imagick', $imageManager->config['driver']); + } + + public function testGetImageManagerWithGd() + { + $server = new ServerFactory([ + 'driver' => 'gd', + ]); + $imageManager = $server->getImageManager(); + + $this->assertInstanceOf('Intervention\Image\ImageManager', $imageManager); } public function testGetImageManagerWithNoneSet() @@ -173,7 +182,6 @@ public function testGetImageManagerWithNoneSet() $imageManager = $server->getImageManager(); $this->assertInstanceOf('Intervention\Image\ImageManager', $imageManager); - $this->assertSame('gd', $imageManager->config['driver']); } public function testGetManipulators() From be8e7522b97d438188dc527bf3ace971714bf3a2 Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 22 Jan 2024 13:09:23 +0100 Subject: [PATCH 05/64] drop php <8.1 in github actions, add php 8.4 --- .github/workflows/test.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 8c230ceb..2011cf67 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -13,7 +13,7 @@ jobs: - uses: actions/checkout@v4 - uses: shivammathur/setup-php@v2 with: - php-version: '7.4' + php-version: '8.3' extensions: gd, imagick - name: php-cs-fixer run: | @@ -25,10 +25,10 @@ jobs: strategy: fail-fast: false matrix: - php-version: ['7.4', '8.0', '8.1', '8.2', '8.3'] + php-version: ['8.1', '8.2', '8.3', '8.4'] prefer-lowest: [''] include: - - php-version: '7.2' + - php-version: '8.1' prefer-lowest: 'prefer-lowest' steps: - uses: actions/checkout@v4 From 5ffd4f8b37d4ff7349081b6b2344dc6ce025275c Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 22 Jan 2024 13:24:10 +0100 Subject: [PATCH 06/64] Fix test for Watermark --- src/Manipulators/Background.php | 2 +- src/Manipulators/BaseManipulator.php | 6 +-- src/Manipulators/Blur.php | 2 +- src/Manipulators/Border.php | 2 +- src/Manipulators/Brightness.php | 2 +- src/Manipulators/Contrast.php | 2 +- src/Manipulators/Crop.php | 2 +- src/Manipulators/Encode.php | 2 +- src/Manipulators/Filter.php | 2 +- src/Manipulators/Flip.php | 2 +- src/Manipulators/Gamma.php | 2 +- src/Manipulators/Helpers/Dimension.php | 8 +-- src/Manipulators/ManipulatorInterface.php | 8 +-- src/Manipulators/Orientation.php | 2 +- src/Manipulators/Pixelate.php | 2 +- src/Manipulators/Sharpen.php | 2 +- src/Manipulators/Size.php | 62 +++++++++++------------ src/Manipulators/Watermark.php | 24 ++++----- tests/Manipulators/WatermarkTest.php | 20 ++++---- 19 files changed, 77 insertions(+), 77 deletions(-) diff --git a/src/Manipulators/Background.php b/src/Manipulators/Background.php index 555a34a3..476a4ea0 100644 --- a/src/Manipulators/Background.php +++ b/src/Manipulators/Background.php @@ -2,7 +2,7 @@ namespace League\Glide\Manipulators; -use Intervention\Image\Image; +use Intervention\Image\Interfaces\ImageInterface; use League\Glide\Manipulators\Helpers\Color; /** diff --git a/src/Manipulators/BaseManipulator.php b/src/Manipulators/BaseManipulator.php index 88345aa8..693e0135 100644 --- a/src/Manipulators/BaseManipulator.php +++ b/src/Manipulators/BaseManipulator.php @@ -2,7 +2,7 @@ namespace League\Glide\Manipulators; -use Intervention\Image\Image; +use Intervention\Image\Interfaces\ImageInterface; abstract class BaseManipulator implements ManipulatorInterface { @@ -44,7 +44,7 @@ public function __get($name) /** * Perform the image manipulation. * - * @return Image The manipulated image. + * @return ImageInterface The manipulated image. */ - abstract public function run(Image $image); + abstract public function run(ImageInterface $image): ImageInterface; } diff --git a/src/Manipulators/Blur.php b/src/Manipulators/Blur.php index c3db393e..b13410f8 100644 --- a/src/Manipulators/Blur.php +++ b/src/Manipulators/Blur.php @@ -2,7 +2,7 @@ namespace League\Glide\Manipulators; -use Intervention\Image\Image; +use Intervention\Image\Interfaces\ImageInterface; /** * @property string $blur diff --git a/src/Manipulators/Border.php b/src/Manipulators/Border.php index 83fd164f..46a2da25 100644 --- a/src/Manipulators/Border.php +++ b/src/Manipulators/Border.php @@ -2,7 +2,7 @@ namespace League\Glide\Manipulators; -use Intervention\Image\Image; +use Intervention\Image\Interfaces\ImageInterface; use League\Glide\Manipulators\Helpers\Color; use League\Glide\Manipulators\Helpers\Dimension; diff --git a/src/Manipulators/Brightness.php b/src/Manipulators/Brightness.php index 2a33544e..9ce7a58e 100644 --- a/src/Manipulators/Brightness.php +++ b/src/Manipulators/Brightness.php @@ -2,7 +2,7 @@ namespace League\Glide\Manipulators; -use Intervention\Image\Image; +use Intervention\Image\Interfaces\ImageInterface; /** * @property string|null $bri diff --git a/src/Manipulators/Contrast.php b/src/Manipulators/Contrast.php index c2cf9140..2924bb97 100644 --- a/src/Manipulators/Contrast.php +++ b/src/Manipulators/Contrast.php @@ -2,7 +2,7 @@ namespace League\Glide\Manipulators; -use Intervention\Image\Image; +use Intervention\Image\Interfaces\ImageInterface; /** * @property string|null $con diff --git a/src/Manipulators/Crop.php b/src/Manipulators/Crop.php index 9a8428df..56bc0d8e 100644 --- a/src/Manipulators/Crop.php +++ b/src/Manipulators/Crop.php @@ -2,7 +2,7 @@ namespace League\Glide\Manipulators; -use Intervention\Image\Image; +use Intervention\Image\Interfaces\ImageInterface; /** * @property string|null $crop diff --git a/src/Manipulators/Encode.php b/src/Manipulators/Encode.php index cad211be..ec9a778e 100644 --- a/src/Manipulators/Encode.php +++ b/src/Manipulators/Encode.php @@ -2,7 +2,7 @@ namespace League\Glide\Manipulators; -use Intervention\Image\Image; +use Intervention\Image\Interfaces\ImageInterface; /** * @property string $fm diff --git a/src/Manipulators/Filter.php b/src/Manipulators/Filter.php index 7d71729e..a381f55e 100644 --- a/src/Manipulators/Filter.php +++ b/src/Manipulators/Filter.php @@ -2,7 +2,7 @@ namespace League\Glide\Manipulators; -use Intervention\Image\Image; +use Intervention\Image\Interfaces\ImageInterface; /** * @property string $filt diff --git a/src/Manipulators/Flip.php b/src/Manipulators/Flip.php index fcec77f8..95ab8e5e 100644 --- a/src/Manipulators/Flip.php +++ b/src/Manipulators/Flip.php @@ -2,7 +2,7 @@ namespace League\Glide\Manipulators; -use Intervention\Image\Image; +use Intervention\Image\Interfaces\ImageInterface; /** * @property string $flip diff --git a/src/Manipulators/Gamma.php b/src/Manipulators/Gamma.php index 035bb8de..eb80cc40 100644 --- a/src/Manipulators/Gamma.php +++ b/src/Manipulators/Gamma.php @@ -2,7 +2,7 @@ namespace League\Glide\Manipulators; -use Intervention\Image\Image; +use Intervention\Image\Interfaces\ImageInterface; /** * @property string|null $gam diff --git a/src/Manipulators/Helpers/Dimension.php b/src/Manipulators/Helpers/Dimension.php index ac9fda4b..d3af526f 100644 --- a/src/Manipulators/Helpers/Dimension.php +++ b/src/Manipulators/Helpers/Dimension.php @@ -2,14 +2,14 @@ namespace League\Glide\Manipulators\Helpers; -use Intervention\Image\Image; +use Intervention\Image\Interfaces\ImageInterface; class Dimension { /** * The source image. * - * @var Image + * @var ImageInterface */ protected $image; @@ -23,10 +23,10 @@ class Dimension /** * Create dimension helper instance. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * @param float $dpr The device pixel ratio. */ - public function __construct(Image $image, $dpr = 1) + public function __construct(ImageInterface $image, $dpr = 1) { $this->image = $image; $this->dpr = $dpr; diff --git a/src/Manipulators/ManipulatorInterface.php b/src/Manipulators/ManipulatorInterface.php index 3b66643e..7bb13ca4 100644 --- a/src/Manipulators/ManipulatorInterface.php +++ b/src/Manipulators/ManipulatorInterface.php @@ -2,7 +2,7 @@ namespace League\Glide\Manipulators; -use Intervention\Image\Image; +use Intervention\Image\Interfaces\ImageInterface; interface ManipulatorInterface { @@ -16,9 +16,9 @@ public function setParams(array $params); /** * Perform the image manipulation. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * - * @return Image The manipulated image. + * @return ImageInterface The manipulated image. */ - public function run(Image $image); + public function run(ImageInterface $image): ImageInterface; } diff --git a/src/Manipulators/Orientation.php b/src/Manipulators/Orientation.php index 231cbebe..cdf8dcf7 100644 --- a/src/Manipulators/Orientation.php +++ b/src/Manipulators/Orientation.php @@ -2,7 +2,7 @@ namespace League\Glide\Manipulators; -use Intervention\Image\Image; +use Intervention\Image\Interfaces\ImageInterface; /** * @property string $or diff --git a/src/Manipulators/Pixelate.php b/src/Manipulators/Pixelate.php index 1de165df..6139c009 100644 --- a/src/Manipulators/Pixelate.php +++ b/src/Manipulators/Pixelate.php @@ -2,7 +2,7 @@ namespace League\Glide\Manipulators; -use Intervention\Image\Image; +use Intervention\Image\Interfaces\ImageInterface; /** * @property string $pixel diff --git a/src/Manipulators/Sharpen.php b/src/Manipulators/Sharpen.php index 4a44a5a3..41f8ede5 100644 --- a/src/Manipulators/Sharpen.php +++ b/src/Manipulators/Sharpen.php @@ -2,7 +2,7 @@ namespace League\Glide\Manipulators; -use Intervention\Image\Image; +use Intervention\Image\Interfaces\ImageInterface; /** * @property string $sharp diff --git a/src/Manipulators/Size.php b/src/Manipulators/Size.php index dd93b55a..fcf04e3a 100644 --- a/src/Manipulators/Size.php +++ b/src/Manipulators/Size.php @@ -2,7 +2,7 @@ namespace League\Glide\Manipulators; -use Intervention\Image\Image; +use Intervention\Image\Interfaces\ImageInterface; /** * @property string $dpr @@ -54,11 +54,11 @@ public function getMaxImageSize() /** * Perform size image manipulation. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * - * @return Image The manipulated image. + * @return ImageInterface The manipulated image. */ - public function run(Image $image) + public function run(ImageInterface $image): ImageInterface { $width = $this->getWidth(); $height = $this->getHeight(); @@ -155,13 +155,13 @@ public function getDpr() /** * Resolve missing image dimensions. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * @param int|null $width The image width. * @param int|null $height The image height. * * @return int[] The resolved width and height. */ - public function resolveMissingDimensions(Image $image, $width, $height) + public function resolveMissingDimensions(ImageInterface $image, $width, $height) { if (is_null($width) and is_null($height)) { $width = $image->width(); @@ -232,14 +232,14 @@ public function limitImageSize($width, $height) /** * Perform resize image manipulation. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * @param string $fit The fit. * @param int $width The width. * @param int $height The height. * - * @return Image The manipulated image. + * @return ImageInterface The manipulated image. */ - public function runResize(Image $image, $fit, $width, $height) + public function runResize(ImageInterface $image, $fit, $width, $height): ImageInterface { if ('contain' === $fit) { return $this->runContainResize($image, $width, $height); @@ -271,13 +271,13 @@ public function runResize(Image $image, $fit, $width, $height) /** * Perform contain resize image manipulation. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * @param int $width The width. * @param int $height The height. * - * @return Image The manipulated image. + * @return ImageInterface The manipulated image. */ - public function runContainResize(Image $image, $width, $height) + public function runContainResize(ImageInterface $image, $width, $height): ImageInterface { return $image->resize($width, $height, function ($constraint) { $constraint->aspectRatio(); @@ -287,13 +287,13 @@ public function runContainResize(Image $image, $width, $height) /** * Perform max resize image manipulation. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * @param int $width The width. * @param int $height The height. * - * @return Image The manipulated image. + * @return ImageInterface The manipulated image. */ - public function runMaxResize(Image $image, $width, $height) + public function runMaxResize(ImageInterface $image, $width, $height): ImageInterface { return $image->resize($width, $height, function ($constraint) { $constraint->aspectRatio(); @@ -304,13 +304,13 @@ public function runMaxResize(Image $image, $width, $height) /** * Perform fill resize image manipulation. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * @param int $width The width. * @param int $height The height. * - * @return Image The manipulated image. + * @return ImageInterface The manipulated image. */ - public function runFillResize($image, $width, $height) + public function runFillResize(ImageInterface $image, $width, $height): ImageInterface { $image = $this->runMaxResize($image, $width, $height); @@ -320,13 +320,13 @@ public function runFillResize($image, $width, $height) /** * Perform fill-max resize image manipulation. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * @param int $width The width. * @param int $height The height. * - * @return Image The manipulated image. + * @return ImageInterface The manipulated image. */ - public function runFillMaxResize(Image $image, $width, $height) + public function runFillMaxResize(ImageInterface $image, $width, $height): ImageInterface { $image = $image->resize($width, $height, function ($constraint) { $constraint->aspectRatio(); @@ -338,13 +338,13 @@ public function runFillMaxResize(Image $image, $width, $height) /** * Perform stretch resize image manipulation. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * @param int $width The width. * @param int $height The height. * - * @return Image The manipulated image. + * @return ImageInterface The manipulated image. */ - public function runStretchResize(Image $image, $width, $height) + public function runStretchResize(ImageInterface $image, $width, $height): ImageInterface { return $image->resize($width, $height); } @@ -352,13 +352,13 @@ public function runStretchResize(Image $image, $width, $height) /** * Perform crop resize image manipulation. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * @param int $width The width. * @param int $height The height. * - * @return Image The manipulated image. + * @return ImageInterface The manipulated image. */ - public function runCropResize(Image $image, $width, $height) + public function runCropResize(ImageInterface $image, $width, $height): ImageInterface { list($resize_width, $resize_height) = $this->resolveCropResizeDimensions($image, $width, $height); @@ -376,13 +376,13 @@ public function runCropResize(Image $image, $width, $height) /** * Resolve the crop resize dimensions. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * @param int $width The width. * @param int $height The height. * * @return array The resize dimensions. */ - public function resolveCropResizeDimensions(Image $image, $width, $height) + public function resolveCropResizeDimensions(ImageInterface $image, $width, $height): array { if ($height > $width * ($image->height() / $image->width())) { return [$height * ($image->width() / $image->height()), $height]; @@ -394,13 +394,13 @@ public function resolveCropResizeDimensions(Image $image, $width, $height) /** * Resolve the crop offset. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * @param int $width The width. * @param int $height The height. * * @return array The crop offset. */ - public function resolveCropOffset(Image $image, $width, $height) + public function resolveCropOffset(ImageInterface $image, $width, $height): array { list($offset_percentage_x, $offset_percentage_y) = $this->getCrop(); diff --git a/src/Manipulators/Watermark.php b/src/Manipulators/Watermark.php index 5e88c843..227c0f49 100644 --- a/src/Manipulators/Watermark.php +++ b/src/Manipulators/Watermark.php @@ -2,7 +2,7 @@ namespace League\Glide\Manipulators; -use Intervention\Image\Image; +use Intervention\Image\Interfaces\ImageInterface; use League\Flysystem\FilesystemException as FilesystemV2Exception; use League\Flysystem\FilesystemOperator; use League\Glide\Filesystem\FilesystemException; @@ -94,11 +94,11 @@ public function getWatermarksPathPrefix() /** * Perform watermark image manipulation. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * - * @return Image The manipulated image. + * @return ImageInterface The manipulated image. */ - public function run(Image $image) + public function run(ImageInterface $image): ImageInterface { if ($watermark = $this->getImage($image)) { $markw = $this->getDimension($image, 'markw'); @@ -135,22 +135,22 @@ public function run(Image $image) /** * Get the watermark image. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * - * @return Image|null The watermark image. + * @return ImageInterface|null The watermark image. */ - public function getImage(Image $image) + public function getImage(ImageInterface $image): ?ImageInterface { if (is_null($this->watermarks)) { - return; + return null; } if (!is_string($this->mark)) { - return; + return null; } if ('' === $this->mark) { - return; + return null; } $path = $this->mark; @@ -173,12 +173,12 @@ public function getImage(Image $image) /** * Get a dimension. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * @param string $field The requested field. * * @return float|null The dimension. */ - public function getDimension(Image $image, $field) + public function getDimension(ImageInterface $image, $field) { if ($this->{$field}) { return (new Dimension($image, $this->getDpr()))->get($this->{$field}); diff --git a/tests/Manipulators/WatermarkTest.php b/tests/Manipulators/WatermarkTest.php index c64ef7b0..7507391e 100644 --- a/tests/Manipulators/WatermarkTest.php +++ b/tests/Manipulators/WatermarkTest.php @@ -51,10 +51,10 @@ public function testGetWatermarksPathPrefix() public function testRun() { - $image = Mockery::mock('Intervention\Image\Image', function ($mock) { + $image = Mockery::mock('Intervention\Image\Interfaces\ImageInterface', function ($mock) { $mock->shouldReceive('insert')->once(); $mock->shouldReceive('getDriver')->andReturn(Mockery::mock('Intervention\Image\AbstractDriver', function ($mock) { - $mock->shouldReceive('init')->with('content')->andReturn(Mockery::mock('Intervention\Image\Image', function ($mock) { + $mock->shouldReceive('init')->with('content')->andReturn(Mockery::mock('Intervention\Image\Interfaces\ImageInterface', function ($mock) { $mock->shouldReceive('width')->andReturn(0)->once(); $mock->shouldReceive('resize')->once(); }))->once(); @@ -74,7 +74,7 @@ public function testRun() ]); $this->assertInstanceOf( - 'Intervention\Image\Image', + 'Intervention\Image\Interfaces\ImageInterface', $this->manipulator->run($image) ); } @@ -99,10 +99,10 @@ public function testGetImage() $driver = Mockery::mock('Intervention\Image\AbstractDriver'); $driver->shouldReceive('init') ->with('content') - ->andReturn(Mockery::mock('Intervention\Image\Image')) + ->andReturn(Mockery::mock('Intervention\Image\Interfaces\ImageInterface')) ->once(); - $image = Mockery::mock('Intervention\Image\Image'); + $image = Mockery::mock('Intervention\Image\Interfaces\ImageInterface'); $image->shouldReceive('getDriver') ->andReturn($driver) ->once(); @@ -125,21 +125,21 @@ public function testGetImageWithUnreadableSource() ->andThrow('League\Flysystem\UnableToReadFile') ->once(); - $image = Mockery::mock('Intervention\Image\Image'); + $image = Mockery::mock('Intervention\Image\Interfaces\ImageInterface'); $this->manipulator->setParams(['mark' => 'image.jpg'])->getImage($image); } public function testGetImageWithoutMarkParam() { - $image = Mockery::mock('Intervention\Image\Image'); + $image = Mockery::mock('Intervention\Image\Interfaces\ImageInterface'); $this->assertNull($this->manipulator->getImage($image)); } public function testGetImageWithEmptyMarkParam() { - $image = Mockery::mock('Intervention\Image\Image'); + $image = Mockery::mock('Intervention\Image\Interfaces\ImageInterface'); $this->assertNull($this->manipulator->setParams(['mark' => ''])->getImage($image)); } @@ -148,14 +148,14 @@ public function testGetImageWithoutWatermarksFilesystem() { $this->manipulator->setWatermarks(null); - $image = Mockery::mock('Intervention\Image\Image'); + $image = Mockery::mock('Intervention\Image\Interfaces\ImageInterface'); $this->assertNull($this->manipulator->setParams(['mark' => 'image.jpg'])->getImage($image)); } public function testGetDimension() { - $image = Mockery::mock('Intervention\Image\Image'); + $image = Mockery::mock('Intervention\Image\Interfaces\ImageInterface'); $image->shouldReceive('width')->andReturn(2000); $image->shouldReceive('height')->andReturn(1000); From 4b26c217fe1de7cf16fbc9c1c96c21e712c25335 Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 22 Jan 2024 13:26:21 +0100 Subject: [PATCH 07/64] Activate github actions on dev branch --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 2011cf67..549385ba 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -4,7 +4,7 @@ on: pull_request: ~ push: branches: - - master + - upgrade-to-glide-3 jobs: coding-style: From ab510fd6b22639e64d2a4b64081d90f839b81823 Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 22 Jan 2024 13:51:26 +0100 Subject: [PATCH 08/64] Upgrade to PHP-CS-Fixer 3 --- .github/workflows/test.yaml | 4 +--- .gitignore | 2 +- .php-cs-fixer.dist.php | 14 ++++++++++++++ .php_cs.dist | 13 ------------- composer.json | 3 ++- 5 files changed, 18 insertions(+), 18 deletions(-) create mode 100644 .php-cs-fixer.dist.php delete mode 100644 .php_cs.dist diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 549385ba..3f93dac0 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -16,9 +16,7 @@ jobs: php-version: '8.3' extensions: gd, imagick - name: php-cs-fixer - run: | - wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.16.4/php-cs-fixer.phar -q - php php-cs-fixer.phar fix --dry-run --diff + run: vendor/bin/php-cs-fixer fix --dry-run --diff tests: runs-on: ubuntu-22.04 diff --git a/.gitignore b/.gitignore index 201c0ad1..74c4b859 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ build vendor docs/_site -.php_cs.cache +.php-cs-fixer.cache .phpunit.result.cache composer.lock diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 00000000..358f818d --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,14 @@ +in('src') + ->in('tests') +; + +return (new PhpCsFixer\Config()) + ->setRules([ + '@Symfony' => true, + 'phpdoc_annotation_without_dot' => false, + ]) + ->setFinder($finder) +; diff --git a/.php_cs.dist b/.php_cs.dist deleted file mode 100644 index d6c057e9..00000000 --- a/.php_cs.dist +++ /dev/null @@ -1,13 +0,0 @@ -in(['src', 'tests']) -; - -return PhpCsFixer\Config::create() - ->setRules(array( - '@Symfony' => true, - 'phpdoc_annotation_without_dot' => false, - )) - ->setFinder($finder) -; diff --git a/composer.json b/composer.json index e2f7ea59..29d60521 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,8 @@ "require-dev": { "mockery/mockery": "^1.3.3", "phpunit/phpunit": "^8.5|^9.0", - "phpunit/php-token-stream": "^3.1|^4.0" + "phpunit/php-token-stream": "^3.1|^4.0", + "friendsofphp/php-cs-fixer": "^3.48" }, "autoload": { "psr-4": { From dfe5153a50d970dbaf73226b5980fa4d1df4bb3f Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 22 Jan 2024 13:53:32 +0100 Subject: [PATCH 09/64] Install php-cs-fixer in github actions --- .github/workflows/test.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 3f93dac0..cd3ed495 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -16,7 +16,9 @@ jobs: php-version: '8.3' extensions: gd, imagick - name: php-cs-fixer - run: vendor/bin/php-cs-fixer fix --dry-run --diff + run: | + composer update --no-interaction --no-ansi --no-progress + vendor/bin/php-cs-fixer fix --dry-run --diff tests: runs-on: ubuntu-22.04 From d876753ff88c946a1f967d2c74d61fd1606827b0 Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 22 Jan 2024 15:10:09 +0100 Subject: [PATCH 10/64] Use new ImageInterface in Size Manipulator --- src/Manipulators/Size.php | 7 ++-- tests/Manipulators/SizeTest.php | 57 ++++++++++++++-------------- tests/Manipulators/WatermarkTest.php | 21 +++++----- 3 files changed, 44 insertions(+), 41 deletions(-) diff --git a/src/Manipulators/Size.php b/src/Manipulators/Size.php index fcf04e3a..437a5695 100644 --- a/src/Manipulators/Size.php +++ b/src/Manipulators/Size.php @@ -2,6 +2,7 @@ namespace League\Glide\Manipulators; +use Intervention\Image\Geometry\Rectangle; use Intervention\Image\Interfaces\ImageInterface; /** @@ -169,13 +170,13 @@ public function resolveMissingDimensions(ImageInterface $image, $width, $height) } if (is_null($width) || is_null($height)) { - $size = (new \Intervention\Image\Size($image->width(), $image->height())) + $size = (new Rectangle($image->width(), $image->height())) ->resize($width, $height, function ($constraint) { $constraint->aspectRatio(); }); - $width = $size->getWidth(); - $height = $size->getHeight(); + $width = $size->width(); + $height = $size->width(); } return [ diff --git a/tests/Manipulators/SizeTest.php b/tests/Manipulators/SizeTest.php index 9d9c074d..b8fccca0 100644 --- a/tests/Manipulators/SizeTest.php +++ b/tests/Manipulators/SizeTest.php @@ -2,6 +2,7 @@ namespace League\Glide\Manipulators; +use Intervention\Image\Interfaces\ImageInterface; use Mockery; use PHPUnit\Framework\TestCase; @@ -41,14 +42,14 @@ public function testGetMaxImageSize() public function testRun() { - $image = Mockery::mock('Intervention\Image\Image', function ($mock) { + $image = Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('width')->andReturn('200')->twice(); $mock->shouldReceive('height')->andReturn('200')->once(); $mock->shouldReceive('resize')->with(100, 100, $this->callback)->andReturn($mock)->once(); }); $this->assertInstanceOf( - 'Intervention\Image\Image', + ImageInterface::class, $this->manipulator->setParams(['w' => 100])->run($image) ); } @@ -117,7 +118,7 @@ public function testGetDpr() public function testResolveMissingDimensions() { - $image = Mockery::mock('Intervention\Image\Image', function ($mock) { + $image = Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('width')->andReturn(400); $mock->shouldReceive('height')->andReturn(200); }); @@ -129,7 +130,7 @@ public function testResolveMissingDimensions() public function testResolveMissingDimensionsWithOddDimensions() { - $image = Mockery::mock('Intervention\Image\Image', function ($mock) { + $image = Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('width')->andReturn(1024); $mock->shouldReceive('height')->andReturn(553); }); @@ -147,7 +148,7 @@ public function testLimitImageSize() public function testRunResize() { - $image = Mockery::mock('Intervention\Image\Image', function ($mock) { + $image = Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('width')->andReturn(100)->times(4); $mock->shouldReceive('height')->andReturn(100)->times(4); $mock->shouldReceive('crop')->andReturn($mock)->once(); @@ -157,93 +158,93 @@ public function testRunResize() }); $this->assertInstanceOf( - 'Intervention\Image\Image', + ImageInterface::class, $this->manipulator->runResize($image, 'contain', 100, 100) ); $this->assertInstanceOf( - 'Intervention\Image\Image', + ImageInterface::class, $this->manipulator->runResize($image, 'fill', 100, 100) ); $this->assertInstanceOf( - 'Intervention\Image\Image', + ImageInterface::class, $this->manipulator->runResize($image, 'fill-max', 100, 100) ); $this->assertInstanceOf( - 'Intervention\Image\Image', + ImageInterface::class, $this->manipulator->runResize($image, 'max', 100, 100) ); $this->assertInstanceOf( - 'Intervention\Image\Image', + ImageInterface::class, $this->manipulator->runResize($image, 'stretch', 100, 100) ); $this->assertInstanceOf( - 'Intervention\Image\Image', + ImageInterface::class, $this->manipulator->runResize($image, 'crop', 100, 100) ); $this->assertInstanceOf( - 'Intervention\Image\Image', + ImageInterface::class, $this->manipulator->runResize($image, 'invalid', 100, 100) ); } public function testRunContainResize() { - $image = Mockery::mock('Intervention\Image\Image', function ($mock) { + $image = Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('resize')->with(100, 100, $this->callback)->andReturn($mock)->once(); }); $this->assertInstanceOf( - 'Intervention\Image\Image', + ImageInterface::class, $this->manipulator->runContainResize($image, 100, 100) ); } public function testRunFillResize() { - $image = Mockery::mock('Intervention\Image\Image', function ($mock) { + $image = Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('resize')->with(100, 100, $this->callback)->andReturn($mock)->once(); $mock->shouldReceive('resizeCanvas')->with(100, 100, 'center')->andReturn($mock)->once(); }); $this->assertInstanceOf( - 'Intervention\Image\Image', + ImageInterface::class, $this->manipulator->runFillResize($image, 100, 100) ); } public function testRunMaxResize() { - $image = Mockery::mock('Intervention\Image\Image', function ($mock) { + $image = Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('resize')->with(100, 100, $this->callback)->andReturn($mock)->once(); }); $this->assertInstanceOf( - 'Intervention\Image\Image', + ImageInterface::class, $this->manipulator->runMaxResize($image, 100, 100) ); } public function testRunStretchResize() { - $image = Mockery::mock('Intervention\Image\Image', function ($mock) { + $image = Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('resize')->with(100, 100)->andReturn($mock)->once(); }); $this->assertInstanceOf( - 'Intervention\Image\Image', + ImageInterface::class, $this->manipulator->runStretchResize($image, 100, 100) ); } public function testRunCropResize() { - $image = Mockery::mock('Intervention\Image\Image', function ($mock) { + $image = Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('width')->andReturn(100)->times(4); $mock->shouldReceive('height')->andReturn(100)->times(4); $mock->shouldReceive('resize')->with(100, 100, $this->callback)->andReturn($mock)->once(); @@ -251,28 +252,28 @@ public function testRunCropResize() }); $this->assertInstanceOf( - 'Intervention\Image\Image', + ImageInterface::class, $this->manipulator->runCropResize($image, 100, 100, 'center') ); } public function testResizeDoesNotRunWhenNoParamsAreSet() { - $image = Mockery::mock('Intervention\Image\Image', function ($mock) { + $image = Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('width')->andReturn(100)->twice(); $mock->shouldReceive('height')->andReturn(100)->twice(); $mock->shouldReceive('resize')->never(); }); $this->assertInstanceOf( - 'Intervention\Image\Image', + ImageInterface::class, $this->manipulator->run($image) ); } public function testResizeDoesNotRunWhenSettingFitCropToCenterWithNoZoom() { - $image = Mockery::mock('Intervention\Image\Image', function ($mock) { + $image = Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('width')->andReturn(100)->twice(); $mock->shouldReceive('height')->andReturn(100)->twice(); $mock->shouldReceive('resize')->never(); @@ -281,14 +282,14 @@ public function testResizeDoesNotRunWhenSettingFitCropToCenterWithNoZoom() $this->manipulator->setParams(['fit' => 'crop-50-50-1']); $this->assertInstanceOf( - 'Intervention\Image\Image', + ImageInterface::class, $this->manipulator->run($image) ); } public function testResizeDoesRunWhenDimensionsAreTheSameAndTheCropZoomIsNotDefaultOne() { - $image = Mockery::mock('Intervention\Image\Image', function ($mock) { + $image = Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('width')->andReturn(100); $mock->shouldReceive('height')->andReturn(100); $mock->shouldReceive('resize')->once(); @@ -298,7 +299,7 @@ public function testResizeDoesRunWhenDimensionsAreTheSameAndTheCropZoomIsNotDefa $this->manipulator->setParams(['fit' => 'crop-50-50-3.2']); $this->assertInstanceOf( - 'Intervention\Image\Image', + ImageInterface::class, $this->manipulator->run($image) ); } diff --git a/tests/Manipulators/WatermarkTest.php b/tests/Manipulators/WatermarkTest.php index 7507391e..dec103db 100644 --- a/tests/Manipulators/WatermarkTest.php +++ b/tests/Manipulators/WatermarkTest.php @@ -2,6 +2,7 @@ namespace League\Glide\Manipulators; +use Intervention\Image\Interfaces\ImageInterface; use League\Glide\Filesystem\FilesystemException; use Mockery; use PHPUnit\Framework\TestCase; @@ -51,10 +52,10 @@ public function testGetWatermarksPathPrefix() public function testRun() { - $image = Mockery::mock('Intervention\Image\Interfaces\ImageInterface', function ($mock) { + $image = Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('insert')->once(); $mock->shouldReceive('getDriver')->andReturn(Mockery::mock('Intervention\Image\AbstractDriver', function ($mock) { - $mock->shouldReceive('init')->with('content')->andReturn(Mockery::mock('Intervention\Image\Interfaces\ImageInterface', function ($mock) { + $mock->shouldReceive('init')->with('content')->andReturn(Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('width')->andReturn(0)->once(); $mock->shouldReceive('resize')->once(); }))->once(); @@ -74,7 +75,7 @@ public function testRun() ]); $this->assertInstanceOf( - 'Intervention\Image\Interfaces\ImageInterface', + ImageInterface::class, $this->manipulator->run($image) ); } @@ -99,10 +100,10 @@ public function testGetImage() $driver = Mockery::mock('Intervention\Image\AbstractDriver'); $driver->shouldReceive('init') ->with('content') - ->andReturn(Mockery::mock('Intervention\Image\Interfaces\ImageInterface')) + ->andReturn(Mockery::mock(ImageInterface::class)) ->once(); - $image = Mockery::mock('Intervention\Image\Interfaces\ImageInterface'); + $image = Mockery::mock(ImageInterface::class); $image->shouldReceive('getDriver') ->andReturn($driver) ->once(); @@ -125,21 +126,21 @@ public function testGetImageWithUnreadableSource() ->andThrow('League\Flysystem\UnableToReadFile') ->once(); - $image = Mockery::mock('Intervention\Image\Interfaces\ImageInterface'); + $image = Mockery::mock(ImageInterface::class); $this->manipulator->setParams(['mark' => 'image.jpg'])->getImage($image); } public function testGetImageWithoutMarkParam() { - $image = Mockery::mock('Intervention\Image\Interfaces\ImageInterface'); + $image = Mockery::mock(ImageInterface::class); $this->assertNull($this->manipulator->getImage($image)); } public function testGetImageWithEmptyMarkParam() { - $image = Mockery::mock('Intervention\Image\Interfaces\ImageInterface'); + $image = Mockery::mock(ImageInterface::class); $this->assertNull($this->manipulator->setParams(['mark' => ''])->getImage($image)); } @@ -148,14 +149,14 @@ public function testGetImageWithoutWatermarksFilesystem() { $this->manipulator->setWatermarks(null); - $image = Mockery::mock('Intervention\Image\Interfaces\ImageInterface'); + $image = Mockery::mock(ImageInterface::class); $this->assertNull($this->manipulator->setParams(['mark' => 'image.jpg'])->getImage($image)); } public function testGetDimension() { - $image = Mockery::mock('Intervention\Image\Interfaces\ImageInterface'); + $image = Mockery::mock(ImageInterface::class); $image->shouldReceive('width')->andReturn(2000); $image->shouldReceive('height')->andReturn(1000); From 50472ffd0299009677ea1c69e2ce03d9467e0a79 Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 22 Jan 2024 15:11:36 +0100 Subject: [PATCH 11/64] Fix tests in Sharpen manipulator --- src/Manipulators/Sharpen.php | 6 +++--- tests/Manipulators/SharpenTest.php | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Manipulators/Sharpen.php b/src/Manipulators/Sharpen.php index 41f8ede5..40ecddaa 100644 --- a/src/Manipulators/Sharpen.php +++ b/src/Manipulators/Sharpen.php @@ -12,11 +12,11 @@ class Sharpen extends BaseManipulator /** * Perform sharpen image manipulation. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * - * @return Image The manipulated image. + * @return ImageInterface The manipulated image. */ - public function run(Image $image) + public function run(ImageInterface $image): ImageInterface { $sharpen = $this->getSharpen(); diff --git a/tests/Manipulators/SharpenTest.php b/tests/Manipulators/SharpenTest.php index d443089f..b7d6608d 100644 --- a/tests/Manipulators/SharpenTest.php +++ b/tests/Manipulators/SharpenTest.php @@ -2,6 +2,7 @@ namespace League\Glide\Manipulators; +use Intervention\Image\Interfaces\ImageInterface; use Mockery; use PHPUnit\Framework\TestCase; @@ -26,12 +27,12 @@ public function testCreateInstance() public function testRun() { - $image = Mockery::mock('Intervention\Image\Image', function ($mock) { + $image = Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('sharpen')->with('10')->once(); }); $this->assertInstanceOf( - 'Intervention\Image\Image', + ImageInterface::class, $this->manipulator->setParams(['sharp' => '10'])->run($image) ); } From 4a221bcf7dfd1f7bb7df85bbd6387645ac347714 Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 22 Jan 2024 15:13:15 +0100 Subject: [PATCH 12/64] Fix tests for Pixelate manipulator --- src/Manipulators/Pixelate.php | 6 +++--- tests/Manipulators/PixelateTest.php | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Manipulators/Pixelate.php b/src/Manipulators/Pixelate.php index 6139c009..573358ce 100644 --- a/src/Manipulators/Pixelate.php +++ b/src/Manipulators/Pixelate.php @@ -12,11 +12,11 @@ class Pixelate extends BaseManipulator /** * Perform pixelate image manipulation. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * - * @return Image The manipulated image. + * @return ImageInterface The manipulated image. */ - public function run(Image $image) + public function run(ImageInterface $image): ImageInterface { $pixelate = $this->getPixelate(); diff --git a/tests/Manipulators/PixelateTest.php b/tests/Manipulators/PixelateTest.php index 3a093db9..3067eb24 100644 --- a/tests/Manipulators/PixelateTest.php +++ b/tests/Manipulators/PixelateTest.php @@ -2,6 +2,7 @@ namespace League\Glide\Manipulators; +use Intervention\Image\Interfaces\ImageInterface; use Mockery; use PHPUnit\Framework\TestCase; @@ -26,12 +27,12 @@ public function testCreateInstance() public function testRun() { - $image = Mockery::mock('Intervention\Image\Image', function ($mock) { + $image = Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('pixelate')->with('10')->once(); }); $this->assertInstanceOf( - 'Intervention\Image\Image', + ImageInterface::class, $this->manipulator->setParams(['pixel' => '10'])->run($image) ); } From b7b9c59a5c4bb1610b56f7d8bf48ffd7ac87abb4 Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 22 Jan 2024 15:16:39 +0100 Subject: [PATCH 13/64] Fix tests for Orientation manipulator --- src/Manipulators/Orientation.php | 6 +++--- tests/Manipulators/OrientationTest.php | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Manipulators/Orientation.php b/src/Manipulators/Orientation.php index cdf8dcf7..30dcfa42 100644 --- a/src/Manipulators/Orientation.php +++ b/src/Manipulators/Orientation.php @@ -12,11 +12,11 @@ class Orientation extends BaseManipulator /** * Perform orientation image manipulation. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * - * @return Image The manipulated image. + * @return ImageInterface The manipulated image. */ - public function run(Image $image) + public function run(ImageInterface $image): ImageInterface { $orientation = $this->getOrientation(); diff --git a/tests/Manipulators/OrientationTest.php b/tests/Manipulators/OrientationTest.php index 2a46ebe0..cbf8098f 100644 --- a/tests/Manipulators/OrientationTest.php +++ b/tests/Manipulators/OrientationTest.php @@ -2,6 +2,7 @@ namespace League\Glide\Manipulators; +use Intervention\Image\Interfaces\ImageInterface; use Mockery; use PHPUnit\Framework\TestCase; @@ -26,18 +27,18 @@ public function testCreateInstance() public function testRun() { - $image = Mockery::mock('Intervention\Image\Image', function ($mock) { + $image = Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('orientate')->andReturn($mock)->once(); $mock->shouldReceive('rotate')->andReturn($mock)->with('90')->once(); }); $this->assertInstanceOf( - 'Intervention\Image\Image', + ImageInterface::class, $this->manipulator->setParams(['or' => 'auto'])->run($image) ); $this->assertInstanceOf( - 'Intervention\Image\Image', + ImageInterface::class, $this->manipulator->setParams(['or' => '90'])->run($image) ); } From 154ebeac352aa9edc5bb7fbcd4374b2e1404f830 Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 22 Jan 2024 15:17:55 +0100 Subject: [PATCH 14/64] Fix tests for Gamma manipulator --- src/Manipulators/Gamma.php | 6 +++--- tests/Manipulators/GammaTest.php | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Manipulators/Gamma.php b/src/Manipulators/Gamma.php index eb80cc40..a3bd6055 100644 --- a/src/Manipulators/Gamma.php +++ b/src/Manipulators/Gamma.php @@ -12,11 +12,11 @@ class Gamma extends BaseManipulator /** * Perform gamma image manipulation. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * - * @return Image The manipulated image. + * @return ImageInterface The manipulated image. */ - public function run(Image $image) + public function run(ImageInterface $image): ImageInterface { $gamma = $this->getGamma(); diff --git a/tests/Manipulators/GammaTest.php b/tests/Manipulators/GammaTest.php index 90c8245b..3c8c6da0 100644 --- a/tests/Manipulators/GammaTest.php +++ b/tests/Manipulators/GammaTest.php @@ -2,6 +2,7 @@ namespace League\Glide\Manipulators; +use Intervention\Image\Interfaces\ImageInterface; use Mockery; use PHPUnit\Framework\TestCase; @@ -26,12 +27,12 @@ public function testCreateInstance() public function testRun() { - $image = Mockery::mock('Intervention\Image\Image', function ($mock) { + $image = Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('gamma')->with('1.5')->once(); }); $this->assertInstanceOf( - 'Intervention\Image\Image', + ImageInterface::class, $this->manipulator->setParams(['gam' => '1.5'])->run($image) ); } From 8397221d9093a10fde7f28e8b0be3242b3145c54 Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 22 Jan 2024 15:18:49 +0100 Subject: [PATCH 15/64] Fix tests for Flip manipulator --- src/Manipulators/Flip.php | 6 +++--- tests/Manipulators/FlipTest.php | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Manipulators/Flip.php b/src/Manipulators/Flip.php index 95ab8e5e..a9203b7a 100644 --- a/src/Manipulators/Flip.php +++ b/src/Manipulators/Flip.php @@ -12,11 +12,11 @@ class Flip extends BaseManipulator /** * Perform flip image manipulation. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * - * @return Image The manipulated image. + * @return ImageInterface The manipulated image. */ - public function run(Image $image) + public function run(ImageInterface $image): ImageInterface { if ($flip = $this->getFlip()) { if ('both' === $flip) { diff --git a/tests/Manipulators/FlipTest.php b/tests/Manipulators/FlipTest.php index 77c50071..273f979e 100644 --- a/tests/Manipulators/FlipTest.php +++ b/tests/Manipulators/FlipTest.php @@ -2,6 +2,7 @@ namespace League\Glide\Manipulators; +use Intervention\Image\Interfaces\ImageInterface; use Mockery; use PHPUnit\Framework\TestCase; @@ -26,18 +27,18 @@ public function testCreateInstance() public function testRun() { - $image = Mockery::mock('Intervention\Image\Image', function ($mock) { + $image = Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('flip')->andReturn($mock)->with('h')->once(); $mock->shouldReceive('flip')->andReturn($mock)->with('v')->once(); }); $this->assertInstanceOf( - 'Intervention\Image\Image', + ImageInterface::class, $this->manipulator->setParams(['flip' => 'h'])->run($image) ); $this->assertInstanceOf( - 'Intervention\Image\Image', + ImageInterface::class, $this->manipulator->setParams(['flip' => 'v'])->run($image) ); } From a1e32002878f581c18cda7b9f0bc14db76a17985 Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 22 Jan 2024 15:20:47 +0100 Subject: [PATCH 16/64] Fix tests for Filter manipulator --- src/Manipulators/Filter.php | 18 +++++++++--------- tests/Manipulators/FilterTest.php | 17 +++++++++-------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/Manipulators/Filter.php b/src/Manipulators/Filter.php index a381f55e..ebcc83f2 100644 --- a/src/Manipulators/Filter.php +++ b/src/Manipulators/Filter.php @@ -12,11 +12,11 @@ class Filter extends BaseManipulator /** * Perform filter image manipulation. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * - * @return Image The manipulated image. + * @return ImageInterface The manipulated image. */ - public function run(Image $image) + public function run(ImageInterface $image): ImageInterface { if ('greyscale' === $this->filt) { return $this->runGreyscaleFilter($image); @@ -32,11 +32,11 @@ public function run(Image $image) /** * Perform greyscale manipulation. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * - * @return Image The manipulated image. + * @return ImageInterface The manipulated image. */ - public function runGreyscaleFilter(Image $image) + public function runGreyscaleFilter(ImageInterface $image): ImageInterface { return $image->greyscale(); } @@ -44,11 +44,11 @@ public function runGreyscaleFilter(Image $image) /** * Perform sepia manipulation. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * - * @return Image The manipulated image. + * @return ImageInterface The manipulated image. */ - public function runSepiaFilter(Image $image) + public function runSepiaFilter(ImageInterface $image): ImageInterface { $image->greyscale(); $image->brightness(-10); diff --git a/tests/Manipulators/FilterTest.php b/tests/Manipulators/FilterTest.php index 6f4ff4cb..0978f107 100644 --- a/tests/Manipulators/FilterTest.php +++ b/tests/Manipulators/FilterTest.php @@ -2,6 +2,7 @@ namespace League\Glide\Manipulators; +use Intervention\Image\Interfaces\ImageInterface; use Mockery; use PHPUnit\Framework\TestCase; @@ -26,7 +27,7 @@ public function testCreateInstance() public function testRun() { - $image = Mockery::mock('Intervention\Image\Image', function ($mock) { + $image = Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('greyscale')->twice()->andReturn($mock) ->shouldReceive('brightness')->with(-10)->twice()->andReturn($mock) ->shouldReceive('contrast')->with(10)->twice()->andReturn($mock) @@ -34,36 +35,36 @@ public function testRun() }); $this->assertInstanceOf( - 'Intervention\Image\Image', + ImageInterface::class, $this->manipulator->setParams(['filt' => 'greyscale'])->run($image) ); $this->assertInstanceOf( - 'Intervention\Image\Image', + ImageInterface::class, $this->manipulator->setParams(['filt' => 'sepia'])->run($image) ); $this->assertInstanceOf( - 'Intervention\Image\Image', + ImageInterface::class, $this->manipulator->setParams([])->run($image) ); } public function testRunGreyscaleFilter() { - $image = Mockery::mock('Intervention\Image\Image', function ($mock) { + $image = Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('greyscale')->andReturn($mock)->once(); }); $this->assertInstanceOf( - 'Intervention\Image\Image', + ImageInterface::class, $this->manipulator->runGreyscaleFilter($image) ); } public function testRunSepiaFilter() { - $image = Mockery::mock('Intervention\Image\Image', function ($mock) { + $image = Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('greyscale')->once()->andReturn($mock) ->shouldReceive('brightness')->with(-10)->twice()->andReturn($mock) ->shouldReceive('contrast')->with(10)->twice()->andReturn($mock) @@ -71,7 +72,7 @@ public function testRunSepiaFilter() }); $this->assertInstanceOf( - 'Intervention\Image\Image', + ImageInterface::class, $this->manipulator->runSepiaFilter($image) ); } From a8ae0ae687830a3dfa50ac00bed9fcb99ae5d85d Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 22 Jan 2024 15:41:42 +0100 Subject: [PATCH 17/64] Update tests for Encode manipulator --- src/Manipulators/Encode.php | 10 +++++----- tests/Manipulators/EncodeTest.php | 26 ++++++++++++++------------ 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/Manipulators/Encode.php b/src/Manipulators/Encode.php index ec9a778e..3439859a 100644 --- a/src/Manipulators/Encode.php +++ b/src/Manipulators/Encode.php @@ -13,11 +13,11 @@ class Encode extends BaseManipulator /** * Perform output image manipulation. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * - * @return Image The manipulated image. + * @return ImageInterface The manipulated image. */ - public function run(Image $image) + public function run(ImageInterface $image): ImageInterface { $format = $this->getFormat($image); $quality = $this->getQuality(); @@ -39,11 +39,11 @@ public function run(Image $image) /** * Resolve format. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * * @return string The resolved format. */ - public function getFormat(Image $image) + public function getFormat(ImageInterface $image) { if (array_key_exists($this->fm, static::supportedFormats())) { return $this->fm; diff --git a/tests/Manipulators/EncodeTest.php b/tests/Manipulators/EncodeTest.php index 8cb3b8c2..449c898f 100644 --- a/tests/Manipulators/EncodeTest.php +++ b/tests/Manipulators/EncodeTest.php @@ -2,7 +2,9 @@ namespace League\Glide\Manipulators; +use Intervention\Image\Encoders\MediaTypeEncoder; use Intervention\Image\ImageManager; +use Intervention\Image\Interfaces\ImageInterface; use Mockery; use PHPUnit\Framework\TestCase; @@ -18,17 +20,17 @@ class EncodeTest extends TestCase public function setUp(): void { - $manager = new ImageManager(); - $this->jpg = $manager->canvas(100, 100)->encode('jpg'); - $this->png = $manager->canvas(100, 100)->encode('png'); - $this->gif = $manager->canvas(100, 100)->encode('gif'); + $manager = ImageManager::gd(); + $this->jpg = $manager->create(100, 100)->encode(new MediaTypeEncoder('image/jpeg')); + $this->png = $manager->create(100, 100)->encode(new MediaTypeEncoder('image/png')); + $this->gif = $manager->create(100, 100)->encode(new MediaTypeEncoder('image/gif')); if (function_exists('imagecreatefromwebp')) { - $this->webp = $manager->canvas(100, 100)->encode('webp'); + $this->webp = $manager->create(100, 100)->encode(new MediaTypeEncoder('webp')); } if (function_exists('imagecreatefromavif')) { - $this->avif = $manager->canvas(100, 100)->encode('avif'); + $this->avif = $manager->create(100, 100)->encode(new MediaTypeEncoder('avif')); } $this->manipulator = new Encode(); @@ -88,7 +90,7 @@ public function testRun() public function testGetFormat() { - $image = Mockery::mock('Intervention\Image\Image', function ($mock) { + $image = Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('mime')->andReturn('image/jpeg')->once(); $mock->shouldReceive('mime')->andReturn('image/png')->once(); $mock->shouldReceive('mime')->andReturn('image/gif')->once(); @@ -145,12 +147,12 @@ public function testWithImagick() 'The imagick extension is not available.' ); } - $manager = new ImageManager(['driver' => 'imagick']); + $manager = ImageManager::imagick(); //These need to be recreated with the imagick driver selected in the manager - $this->jpg = $manager->canvas(100, 100)->encode('jpg'); - $this->png = $manager->canvas(100, 100)->encode('png'); - $this->gif = $manager->canvas(100, 100)->encode('gif'); - $this->tif = $manager->canvas(100, 100)->encode('tiff'); + $this->jpg = $manager->create(100, 100)->encode(new MediaTypeEncoder('image/jpeg')); + $this->png = $manager->create(100, 100)->encode(new MediaTypeEncoder('image/png')); + $this->gif = $manager->create(100, 100)->encode(new MediaTypeEncoder('image/gif')); + $this->tif = $manager->create(100, 100)->encode(new MediaTypeEncoder('image/tiff')); $this->assertSame('image/tiff', $this->manipulator->setParams(['fm' => 'tiff'])->run($this->jpg)->mime); $this->assertSame('image/tiff', $this->manipulator->setParams(['fm' => 'tiff'])->run($this->png)->mime); From 43ba3cd7a9cc725b5499af53e8dcfb9b77606f9d Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 22 Jan 2024 15:45:00 +0100 Subject: [PATCH 18/64] Update tests for Crop manipulator --- src/Manipulators/Crop.php | 18 +++++++++--------- tests/Manipulators/CropTest.php | 5 +++-- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/Manipulators/Crop.php b/src/Manipulators/Crop.php index 56bc0d8e..6770a3ca 100644 --- a/src/Manipulators/Crop.php +++ b/src/Manipulators/Crop.php @@ -12,11 +12,11 @@ class Crop extends BaseManipulator /** * Perform crop image manipulation. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * - * @return Image The manipulated image. + * @return ImageInterface The manipulated image. */ - public function run(Image $image) + public function run(ImageInterface $image): ImageInterface { $coordinates = $this->getCoordinates($image); @@ -37,16 +37,16 @@ public function run(Image $image) /** * Resolve coordinates. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * * @return int[]|null The resolved coordinates. * * @psalm-return array{0: int, 1: int, 2: int, 3: int}|null */ - public function getCoordinates(Image $image) + public function getCoordinates(ImageInterface $image): ?array { if (null === $this->crop) { - return; + return null; } $coordinates = explode(',', $this->crop); @@ -62,7 +62,7 @@ public function getCoordinates(Image $image) ($coordinates[3] < 0) or ($coordinates[2] >= $image->width()) or ($coordinates[3] >= $image->height())) { - return; + return null; } return [ @@ -76,12 +76,12 @@ public function getCoordinates(Image $image) /** * Limit coordinates to image boundaries. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * @param int[] $coordinates The coordinates. * * @return int[] The limited coordinates. */ - public function limitToImageBoundaries(Image $image, array $coordinates) + public function limitToImageBoundaries(ImageInterface $image, array $coordinates): array { if ($coordinates[0] > ($image->width() - $coordinates[2])) { $coordinates[0] = $image->width() - $coordinates[2]; diff --git a/tests/Manipulators/CropTest.php b/tests/Manipulators/CropTest.php index 05ff0de8..fded9c77 100644 --- a/tests/Manipulators/CropTest.php +++ b/tests/Manipulators/CropTest.php @@ -2,6 +2,7 @@ namespace League\Glide\Manipulators; +use Intervention\Image\Interfaces\ImageInterface; use Mockery; use PHPUnit\Framework\TestCase; @@ -13,7 +14,7 @@ class CropTest extends TestCase public function setUp(): void { $this->manipulator = new Crop(); - $this->image = Mockery::mock('Intervention\Image\Image', function ($mock) { + $this->image = Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('width')->andReturn(100); $mock->shouldReceive('height')->andReturn(100); }); @@ -34,7 +35,7 @@ public function testRun() $this->image->shouldReceive('crop')->with(100, 100, 0, 0)->once(); $this->assertInstanceOf( - 'Intervention\Image\Image', + ImageInterface::class, $this->manipulator->setParams(['crop' => '100,100,0,0'])->run($this->image) ); } From 8b5239b1b2ac3807aecb5ec34301c9c7c3c9ebf0 Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 22 Jan 2024 15:46:37 +0100 Subject: [PATCH 19/64] Update tests for Contrast manipulator --- src/Manipulators/Contrast.php | 6 +++--- tests/Manipulators/ContrastTest.php | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Manipulators/Contrast.php b/src/Manipulators/Contrast.php index 2924bb97..e009565e 100644 --- a/src/Manipulators/Contrast.php +++ b/src/Manipulators/Contrast.php @@ -12,11 +12,11 @@ class Contrast extends BaseManipulator /** * Perform contrast image manipulation. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * - * @return Image The manipulated image. + * @return ImageInterface The manipulated image. */ - public function run(Image $image) + public function run(ImageInterface $image): ImageInterface { $contrast = $this->getContrast(); diff --git a/tests/Manipulators/ContrastTest.php b/tests/Manipulators/ContrastTest.php index 724a38cc..7a1e588f 100644 --- a/tests/Manipulators/ContrastTest.php +++ b/tests/Manipulators/ContrastTest.php @@ -2,6 +2,7 @@ namespace League\Glide\Manipulators; +use Intervention\Image\Interfaces\ImageInterface; use Mockery; use PHPUnit\Framework\TestCase; @@ -26,12 +27,12 @@ public function testCreateInstance() public function testRun() { - $image = Mockery::mock('Intervention\Image\Image', function ($mock) { + $image = Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('contrast')->with('50')->once(); }); $this->assertInstanceOf( - 'Intervention\Image\Image', + ImageInterface::class, $this->manipulator->setParams(['con' => 50])->run($image) ); } From 7f8716481e8af159b61080b8e6e5c1c3c4e4d8d9 Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 22 Jan 2024 15:48:26 +0100 Subject: [PATCH 20/64] Update tests for Brightness manipulator --- src/Manipulators/Brightness.php | 6 +++--- tests/Manipulators/BrightnessTest.php | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Manipulators/Brightness.php b/src/Manipulators/Brightness.php index 9ce7a58e..35e13301 100644 --- a/src/Manipulators/Brightness.php +++ b/src/Manipulators/Brightness.php @@ -12,11 +12,11 @@ class Brightness extends BaseManipulator /** * Perform brightness image manipulation. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * - * @return Image The manipulated image. + * @return ImageInterface The manipulated image. */ - public function run(Image $image) + public function run(ImageInterface $image): ImageInterface { $brightness = $this->getBrightness(); diff --git a/tests/Manipulators/BrightnessTest.php b/tests/Manipulators/BrightnessTest.php index 076ea54c..11282404 100644 --- a/tests/Manipulators/BrightnessTest.php +++ b/tests/Manipulators/BrightnessTest.php @@ -2,6 +2,7 @@ namespace League\Glide\Manipulators; +use Intervention\Image\Interfaces\ImageInterface; use Mockery; use PHPUnit\Framework\TestCase; @@ -26,12 +27,12 @@ public function testCreateInstance() public function testRun() { - $image = Mockery::mock('Intervention\Image\Image', function ($mock) { + $image = Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('brightness')->with('50')->once(); }); $this->assertInstanceOf( - 'Intervention\Image\Image', + ImageInterface::class, $this->manipulator->setParams(['bri' => 50])->run($image) ); } From 88f132479e289a9ae03a58cb191986f2be47dc96 Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 22 Jan 2024 15:52:35 +0100 Subject: [PATCH 21/64] Update tests for Border manipulator --- src/Manipulators/Border.php | 36 ++++++++++++++------------ src/Manipulators/Helpers/Dimension.php | 2 ++ tests/Manipulators/BorderTest.php | 23 ++++++++-------- 3 files changed, 33 insertions(+), 28 deletions(-) diff --git a/src/Manipulators/Border.php b/src/Manipulators/Border.php index 46a2da25..e87e132f 100644 --- a/src/Manipulators/Border.php +++ b/src/Manipulators/Border.php @@ -15,11 +15,11 @@ class Border extends BaseManipulator /** * Perform border image manipulation. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * - * @return Image The manipulated image. + * @return ImageInterface The manipulated image. */ - public function run(Image $image) + public function run(ImageInterface $image): ImageInterface { if ($border = $this->getBorder($image)) { list($width, $color, $method) = $border; @@ -43,16 +43,16 @@ public function run(Image $image) /** * Resolve border amount. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * * @return (float|string)[]|null The resolved border amount. * * @psalm-return array{0: float, 1: string, 2: string}|null */ - public function getBorder(Image $image) + public function getBorder(ImageInterface $image): ?array { if (!$this->border) { - return; + return null; } $values = explode(',', $this->border); @@ -64,18 +64,20 @@ public function getBorder(Image $image) if ($width) { return [$width, $color, $method]; } + + return null; } /** * Get border width. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * @param float $dpr The device pixel ratio. * @param string $width The border width. * * @return float|null The resolved border width. */ - public function getWidth(Image $image, $dpr, $width) + public function getWidth(ImageInterface $image, $dpr, $width): ?float { return (new Dimension($image, $dpr))->get($width); } @@ -129,13 +131,13 @@ public function getDpr() /** * Run the overlay border method. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * @param float $width The border width. * @param string $color The border color. * - * @return Image The manipulated image. + * @return ImageInterface The manipulated image. */ - public function runOverlay(Image $image, $width, $color) + public function runOverlay(ImageInterface $image, $width, $color): ImageInterface { return $image->rectangle( (int) round($width / 2), @@ -151,13 +153,13 @@ function ($draw) use ($width, $color) { /** * Run the shrink border method. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * @param float $width The border width. * @param string $color The border color. * - * @return Image The manipulated image. + * @return ImageInterface The manipulated image. */ - public function runShrink(Image $image, $width, $color) + public function runShrink(ImageInterface $image, $width, $color): ImageInterface { return $image ->resize( @@ -176,13 +178,13 @@ public function runShrink(Image $image, $width, $color) /** * Run the expand border method. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * @param float $width The border width. * @param string $color The border color. * - * @return Image The manipulated image. + * @return ImageInterface The manipulated image. */ - public function runExpand(Image $image, $width, $color) + public function runExpand(ImageInterface $image, $width, $color): ImageInterface { return $image->resizeCanvas( (int) round($width * 2), diff --git a/src/Manipulators/Helpers/Dimension.php b/src/Manipulators/Helpers/Dimension.php index d3af526f..5614832e 100644 --- a/src/Manipulators/Helpers/Dimension.php +++ b/src/Manipulators/Helpers/Dimension.php @@ -52,5 +52,7 @@ public function get($value) return (float) $this->image->width() * ((float) $matches[1] / 100); } + + return null; } } diff --git a/tests/Manipulators/BorderTest.php b/tests/Manipulators/BorderTest.php index 3683c6a6..5438ba64 100644 --- a/tests/Manipulators/BorderTest.php +++ b/tests/Manipulators/BorderTest.php @@ -2,6 +2,7 @@ namespace League\Glide\Manipulators; +use Intervention\Image\Interfaces\ImageInterface; use Mockery; use PHPUnit\Framework\TestCase; @@ -21,7 +22,7 @@ public function testCreateInstance() public function testGetBorder() { - $image = Mockery::mock('Intervention\Image\Image'); + $image = Mockery::mock(ImageInterface::class); $border = new Border(); @@ -35,7 +36,7 @@ public function testGetBorder() public function testGetInvalidBorder() { - $image = Mockery::mock('Intervention\Image\Image'); + $image = Mockery::mock(ImageInterface::class); $border = new Border(); @@ -46,7 +47,7 @@ public function testGetInvalidBorder() public function testGetWidth() { - $image = Mockery::mock('Intervention\Image\Image'); + $image = Mockery::mock(ImageInterface::class); $border = new Border(); @@ -82,16 +83,16 @@ public function testGetDpr() public function testRunWithNoBorder() { - $image = Mockery::mock('Intervention\Image\Image'); + $image = Mockery::mock(ImageInterface::class); $border = new Border(); - $this->assertInstanceOf('Intervention\Image\Image', $border->run($image)); + $this->assertInstanceOf(ImageInterface::class, $border->run($image)); } public function testRunOverlay() { - $image = Mockery::mock('Intervention\Image\Image', function ($mock) { + $image = Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('width')->andReturn(100)->once(); $mock->shouldReceive('height')->andReturn(100)->once(); $mock->shouldReceive('rectangle')->with(5, 5, 95, 95, Mockery::on(function ($closure) { @@ -102,12 +103,12 @@ public function testRunOverlay() $border = new Border(); $border->setParams(['border' => '10,5000,overlay']); - $this->assertInstanceOf('Intervention\Image\Image', $border->run($image)); + $this->assertInstanceOf(ImageInterface::class, $border->run($image)); } public function testRunShrink() { - $image = Mockery::mock('Intervention\Image\Image', function ($mock) { + $image = Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('width')->andReturn(100)->once(); $mock->shouldReceive('height')->andReturn(100)->once(); $mock->shouldReceive('resize')->with(80, 80)->andReturn($mock)->once(); @@ -117,18 +118,18 @@ public function testRunShrink() $border = new Border(); $border->setParams(['border' => '10,5000,shrink']); - $this->assertInstanceOf('Intervention\Image\Image', $border->run($image)); + $this->assertInstanceOf(ImageInterface::class, $border->run($image)); } public function testRunExpand() { - $image = Mockery::mock('Intervention\Image\Image', function ($mock) { + $image = Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('resizeCanvas')->with(20, 20, 'center', true, 'rgba(0, 0, 0, 0.5)')->andReturn($mock)->once(); }); $border = new Border(); $border->setParams(['border' => '10,5000,expand']); - $this->assertInstanceOf('Intervention\Image\Image', $border->run($image)); + $this->assertInstanceOf(ImageInterface::class, $border->run($image)); } } From 87e421498fa9393c6f7e29b7e32e3b131f6116ca Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 22 Jan 2024 15:53:48 +0100 Subject: [PATCH 22/64] Update tests for Blur manipulator --- src/Manipulators/Blur.php | 6 +++--- tests/Manipulators/BlurTest.php | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Manipulators/Blur.php b/src/Manipulators/Blur.php index b13410f8..2a5f4ce4 100644 --- a/src/Manipulators/Blur.php +++ b/src/Manipulators/Blur.php @@ -12,11 +12,11 @@ class Blur extends BaseManipulator /** * Perform blur image manipulation. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * - * @return Image The manipulated image. + * @return ImageInterface The manipulated image. */ - public function run(Image $image) + public function run(ImageInterface $image): ImageInterface { $blur = $this->getBlur(); diff --git a/tests/Manipulators/BlurTest.php b/tests/Manipulators/BlurTest.php index 6e15a536..46c65b98 100644 --- a/tests/Manipulators/BlurTest.php +++ b/tests/Manipulators/BlurTest.php @@ -2,6 +2,7 @@ namespace League\Glide\Manipulators; +use Intervention\Image\Interfaces\ImageInterface; use Mockery; use PHPUnit\Framework\TestCase; @@ -26,12 +27,12 @@ public function testCreateInstance() public function testRun() { - $image = Mockery::mock('Intervention\Image\Image', function ($mock) { + $image = Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('blur')->with('10')->once(); }); $this->assertInstanceOf( - 'Intervention\Image\Image', + ImageInterface::class, $this->manipulator->setParams(['blur' => 10])->run($image) ); } From 71226943217e64668d215ddb051afac1b4b7fee0 Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 22 Jan 2024 15:57:44 +0100 Subject: [PATCH 23/64] fix tests for Background manipulator --- src/Manipulators/Background.php | 6 +++--- tests/Manipulators/BackgroundTest.php | 9 +++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Manipulators/Background.php b/src/Manipulators/Background.php index 476a4ea0..0c17c3cc 100644 --- a/src/Manipulators/Background.php +++ b/src/Manipulators/Background.php @@ -13,11 +13,11 @@ class Background extends BaseManipulator /** * Perform background image manipulation. * - * @param Image $image The source image. + * @param ImageInterface $image The source image. * - * @return Image The manipulated image. + * @return ImageInterface The manipulated image. */ - public function run(Image $image) + public function run(ImageInterface $image): ImageInterface { if (is_null($this->bg)) { return $image; diff --git a/tests/Manipulators/BackgroundTest.php b/tests/Manipulators/BackgroundTest.php index 8fdd6c02..8bbdab27 100644 --- a/tests/Manipulators/BackgroundTest.php +++ b/tests/Manipulators/BackgroundTest.php @@ -2,6 +2,7 @@ namespace League\Glide\Manipulators; +use Intervention\Image\Interfaces\ImageInterface; use Mockery; use PHPUnit\Framework\TestCase; @@ -21,11 +22,11 @@ public function testCreateInstance() public function testRun() { - $image = Mockery::mock('Intervention\Image\Image', function ($mock) { + $image = Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('width')->andReturn(100)->once(); $mock->shouldReceive('height')->andReturn(100)->once(); $mock->shouldReceive('getDriver')->andReturn(Mockery::mock('Intervention\Image\AbstractDriver', function ($mock) { - $mock->shouldReceive('newImage')->with(100, 100, 'rgba(0, 0, 0, 1)')->andReturn(Mockery::mock('Intervention\Image\Image', function ($mock) { + $mock->shouldReceive('newImage')->with(100, 100, 'rgba(0, 0, 0, 1)')->andReturn(Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('insert')->andReturn($mock)->once(); }))->once(); }))->once(); @@ -33,7 +34,7 @@ public function testRun() $border = new Background(); - $this->assertInstanceOf('Intervention\Image\Image', $border->run($image)); - $this->assertInstanceOf('Intervention\Image\Image', $border->setParams(['bg' => 'black'])->run($image)); + $this->assertInstanceOf(ImageInterface::class, $border->run($image)); + $this->assertInstanceOf(ImageInterface::class, $border->setParams(['bg' => 'black'])->run($image)); } } From c25ef4d5ca8dbb88c0551096ffa5b272205c9903 Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 22 Jan 2024 15:59:18 +0100 Subject: [PATCH 24/64] fix tests for Dimension helper --- tests/Manipulators/Helpers/DimensionTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Manipulators/Helpers/DimensionTest.php b/tests/Manipulators/Helpers/DimensionTest.php index 0d45b17c..dba8645a 100644 --- a/tests/Manipulators/Helpers/DimensionTest.php +++ b/tests/Manipulators/Helpers/DimensionTest.php @@ -2,6 +2,7 @@ namespace League\Glide\Manipulators\Helpers; +use Intervention\Image\Interfaces\ImageInterface; use Mockery; use PHPUnit\Framework\TestCase; @@ -11,7 +12,7 @@ class DimensionTest extends TestCase public function setUp(): void { - $this->image = Mockery::mock('Intervention\Image\Image'); + $this->image = Mockery::mock(ImageInterface::class); } public function tearDown(): void From ca4f4cf7efbf57834587d627a84e0df10cfa9e61 Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 22 Jan 2024 16:09:28 +0100 Subject: [PATCH 25/64] Fix tests in ApiTest --- src/Api/Api.php | 2 +- tests/Api/ApiTest.php | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Api/Api.php b/src/Api/Api.php index 54e7065f..7b0bcea4 100644 --- a/src/Api/Api.php +++ b/src/Api/Api.php @@ -94,7 +94,7 @@ public function getManipulators() */ public function run($source, array $params) { - $image = $this->imageManager->make($source); + $image = $this->imageManager->read($source); foreach ($this->manipulators as $manipulator) { $manipulator->setParams($params); diff --git a/tests/Api/ApiTest.php b/tests/Api/ApiTest.php index 8e22d0ee..dd8250ad 100644 --- a/tests/Api/ApiTest.php +++ b/tests/Api/ApiTest.php @@ -2,6 +2,8 @@ namespace League\Glide\Api; +use Intervention\Image\ImageManager; +use Intervention\Image\Interfaces\ImageInterface; use InvalidArgumentException; use Mockery; use PHPUnit\Framework\TestCase; @@ -12,7 +14,7 @@ class ApiTest extends TestCase public function setUp(): void { - $this->api = new Api(Mockery::mock('Intervention\Image\ImageManager'), []); + $this->api = new Api(ImageManager::gd(), []); } public function tearDown(): void @@ -27,13 +29,13 @@ public function testCreateInstance() public function testSetImageManager() { - $this->api->setImageManager(Mockery::mock('Intervention\Image\ImageManager')); - $this->assertInstanceOf('Intervention\Image\ImageManager', $this->api->getImageManager()); + $this->api->setImageManager(ImageManager::gd()); + $this->assertInstanceOf(ImageManager::class, $this->api->getImageManager()); } public function testGetImageManager() { - $this->assertInstanceOf('Intervention\Image\ImageManager', $this->api->getImageManager()); + $this->assertInstanceOf(ImageManager::class, $this->api->getImageManager()); } public function testSetManipulators() @@ -58,13 +60,11 @@ public function testGetManipulators() public function testRun() { - $image = Mockery::mock('Intervention\Image\Image', function ($mock) { + $image = Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('getEncoded')->andReturn('encoded'); }); - $manager = Mockery::mock('Intervention\Image\ImageManager', function ($mock) use ($image) { - $mock->shouldReceive('make')->andReturn($image); - }); + $manager = ImageManager::gd(); $manipulator = Mockery::mock('League\Glide\Manipulators\ManipulatorInterface', function ($mock) use ($image) { $mock->shouldReceive('setParams')->with([]); From 865cc260e11381fde4a2d8ade12137450c4a203e Mon Sep 17 00:00:00 2001 From: Art4 Date: Wed, 24 Jan 2024 13:08:58 +0100 Subject: [PATCH 26/64] Fix Background manipulator --- src/Manipulators/Background.php | 7 ++++--- tests/Manipulators/BackgroundTest.php | 9 ++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Manipulators/Background.php b/src/Manipulators/Background.php index 0c17c3cc..fdfeb6d2 100644 --- a/src/Manipulators/Background.php +++ b/src/Manipulators/Background.php @@ -26,9 +26,10 @@ public function run(ImageInterface $image): ImageInterface $color = (new Color($this->bg))->formatted(); if ($color) { - $new = $image->getDriver()->newImage($image->width(), $image->height(), $color); - $new->mime = $image->mime; - $image = $new->insert($image, 'top-left', 0, 0); + $new = $image->driver()->createImage($image->width(), $image->height())->fill($color); + // TODO: Find a way to communicate the mime + // $new->mime = $image->mime; + $image = $new->place($image, 'top-left', 0, 0); } return $image; diff --git a/tests/Manipulators/BackgroundTest.php b/tests/Manipulators/BackgroundTest.php index 8bbdab27..2f7f7dcc 100644 --- a/tests/Manipulators/BackgroundTest.php +++ b/tests/Manipulators/BackgroundTest.php @@ -2,6 +2,7 @@ namespace League\Glide\Manipulators; +use Intervention\Image\Interfaces\DriverInterface; use Intervention\Image\Interfaces\ImageInterface; use Mockery; use PHPUnit\Framework\TestCase; @@ -25,9 +26,11 @@ public function testRun() $image = Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('width')->andReturn(100)->once(); $mock->shouldReceive('height')->andReturn(100)->once(); - $mock->shouldReceive('getDriver')->andReturn(Mockery::mock('Intervention\Image\AbstractDriver', function ($mock) { - $mock->shouldReceive('newImage')->with(100, 100, 'rgba(0, 0, 0, 1)')->andReturn(Mockery::mock(ImageInterface::class, function ($mock) { - $mock->shouldReceive('insert')->andReturn($mock)->once(); + $mock->shouldReceive('driver')->andReturn(Mockery::mock(DriverInterface::class, function ($mock) { + $mock->shouldReceive('createImage')->with(100, 100)->andReturn(Mockery::mock(ImageInterface::class, function ($mock) { + $mock->shouldReceive('fill')->with('rgba(0, 0, 0, 1)')->andReturn(Mockery::mock(ImageInterface::class, function ($mock) { + $mock->shouldReceive('place')->andReturn($mock)->once(); + }))->once(); }))->once(); }))->once(); }); From 69e4151697e8cd37f1389a2c087f0ef633d250e1 Mon Sep 17 00:00:00 2001 From: Art4 Date: Wed, 24 Jan 2024 13:54:15 +0100 Subject: [PATCH 27/64] Fix watermark manipulator --- src/Manipulators/Watermark.php | 4 ++-- src/ServerFactory.php | 2 -- tests/Manipulators/WatermarkTest.php | 13 +++++++------ 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Manipulators/Watermark.php b/src/Manipulators/Watermark.php index 227c0f49..1109933e 100644 --- a/src/Manipulators/Watermark.php +++ b/src/Manipulators/Watermark.php @@ -126,7 +126,7 @@ public function run(ImageInterface $image): ImageInterface $watermark->opacity($markalpha); } - $image->insert($watermark, $markpos, intval($markx), intval($marky)); + $image->place($watermark, $markpos, intval($markx), intval($marky)); } return $image; @@ -163,7 +163,7 @@ public function getImage(ImageInterface $image): ?ImageInterface if ($this->watermarks->fileExists($path)) { $source = $this->watermarks->read($path); - return $image->getDriver()->init($source); + return $image->driver()->handleInput($source); } } catch (FilesystemV2Exception $exception) { throw new FilesystemException('Could not read the image `'.$path.'`.'); diff --git a/src/ServerFactory.php b/src/ServerFactory.php index 8a925b1d..0faa3eb5 100644 --- a/src/ServerFactory.php +++ b/src/ServerFactory.php @@ -2,8 +2,6 @@ namespace League\Glide; -use Intervention\Image\Drivers\Gd\Driver as GdDriver; -use Intervention\Image\Drivers\Imagick\Driver as ImagickDriver; use Intervention\Image\ImageManager; use InvalidArgumentException; use League\Flysystem\Filesystem; diff --git a/tests/Manipulators/WatermarkTest.php b/tests/Manipulators/WatermarkTest.php index dec103db..c392eee0 100644 --- a/tests/Manipulators/WatermarkTest.php +++ b/tests/Manipulators/WatermarkTest.php @@ -2,6 +2,7 @@ namespace League\Glide\Manipulators; +use Intervention\Image\Interfaces\DriverInterface; use Intervention\Image\Interfaces\ImageInterface; use League\Glide\Filesystem\FilesystemException; use Mockery; @@ -53,9 +54,9 @@ public function testGetWatermarksPathPrefix() public function testRun() { $image = Mockery::mock(ImageInterface::class, function ($mock) { - $mock->shouldReceive('insert')->once(); - $mock->shouldReceive('getDriver')->andReturn(Mockery::mock('Intervention\Image\AbstractDriver', function ($mock) { - $mock->shouldReceive('init')->with('content')->andReturn(Mockery::mock(ImageInterface::class, function ($mock) { + $mock->shouldReceive('place')->once(); + $mock->shouldReceive('driver')->andReturn(Mockery::mock(DriverInterface::class, function ($mock) { + $mock->shouldReceive('handleInput')->with('content')->andReturn(Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('width')->andReturn(0)->once(); $mock->shouldReceive('resize')->once(); }))->once(); @@ -97,14 +98,14 @@ public function testGetImage() $this->manipulator->setWatermarksPathPrefix('watermarks'); - $driver = Mockery::mock('Intervention\Image\AbstractDriver'); - $driver->shouldReceive('init') + $driver = Mockery::mock(DriverInterface::class); + $driver->shouldReceive('handleInput') ->with('content') ->andReturn(Mockery::mock(ImageInterface::class)) ->once(); $image = Mockery::mock(ImageInterface::class); - $image->shouldReceive('getDriver') + $image->shouldReceive('driver') ->andReturn($driver) ->once(); From 44413aa48a90fb544431a247dc5cda7eabdc0c77 Mon Sep 17 00:00:00 2001 From: Art4 Date: Wed, 24 Jan 2024 14:27:14 +0100 Subject: [PATCH 28/64] Fix size manipulator --- src/Manipulators/Size.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Manipulators/Size.php b/src/Manipulators/Size.php index 437a5695..3f4a68a6 100644 --- a/src/Manipulators/Size.php +++ b/src/Manipulators/Size.php @@ -171,12 +171,10 @@ public function resolveMissingDimensions(ImageInterface $image, $width, $height) if (is_null($width) || is_null($height)) { $size = (new Rectangle($image->width(), $image->height())) - ->resize($width, $height, function ($constraint) { - $constraint->aspectRatio(); - }); + ->resize($width, $height); $width = $size->width(); - $height = $size->width(); + $height = $size->height(); } return [ From 56504cc822b499bbfac35f318435307dc2422e7c Mon Sep 17 00:00:00 2001 From: Art4 Date: Wed, 24 Jan 2024 14:46:20 +0100 Subject: [PATCH 29/64] Fix tests in size manipulator --- src/Manipulators/Size.php | 23 +++++++---------------- tests/Manipulators/SizeTest.php | 16 ++++++++-------- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/src/Manipulators/Size.php b/src/Manipulators/Size.php index 3f4a68a6..ccba4ad4 100644 --- a/src/Manipulators/Size.php +++ b/src/Manipulators/Size.php @@ -171,7 +171,7 @@ public function resolveMissingDimensions(ImageInterface $image, $width, $height) if (is_null($width) || is_null($height)) { $size = (new Rectangle($image->width(), $image->height())) - ->resize($width, $height); + ->scale($width, $height); $width = $size->width(); $height = $size->height(); @@ -278,9 +278,7 @@ public function runResize(ImageInterface $image, $fit, $width, $height): ImageIn */ public function runContainResize(ImageInterface $image, $width, $height): ImageInterface { - return $image->resize($width, $height, function ($constraint) { - $constraint->aspectRatio(); - }); + return $image->resize($width, $height); } /** @@ -294,10 +292,7 @@ public function runContainResize(ImageInterface $image, $width, $height): ImageI */ public function runMaxResize(ImageInterface $image, $width, $height): ImageInterface { - return $image->resize($width, $height, function ($constraint) { - $constraint->aspectRatio(); - $constraint->upsize(); - }); + return $image->resize($width, $height); } /** @@ -313,7 +308,7 @@ public function runFillResize(ImageInterface $image, $width, $height): ImageInte { $image = $this->runMaxResize($image, $width, $height); - return $image->resizeCanvas($width, $height, 'center'); + return $image->resizeCanvas($width, $height, 'ffffff', 'center'); } /** @@ -327,11 +322,9 @@ public function runFillResize(ImageInterface $image, $width, $height): ImageInte */ public function runFillMaxResize(ImageInterface $image, $width, $height): ImageInterface { - $image = $image->resize($width, $height, function ($constraint) { - $constraint->aspectRatio(); - }); + $image = $image->resize($width, $height); - return $image->resizeCanvas($width, $height, 'center'); + return $image->resizeCanvas($width, $height, 'ffffff', 'center'); } /** @@ -363,9 +356,7 @@ public function runCropResize(ImageInterface $image, $width, $height): ImageInte $zoom = $this->getCrop()[2]; - $image->resize($resize_width * $zoom, $resize_height * $zoom, function ($constraint) { - $constraint->aspectRatio(); - }); + $image->resize($resize_width * $zoom, $resize_height * $zoom); list($offset_x, $offset_y) = $this->resolveCropOffset($image, $width, $height); diff --git a/tests/Manipulators/SizeTest.php b/tests/Manipulators/SizeTest.php index b8fccca0..edeaf9e6 100644 --- a/tests/Manipulators/SizeTest.php +++ b/tests/Manipulators/SizeTest.php @@ -45,7 +45,7 @@ public function testRun() $image = Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('width')->andReturn('200')->twice(); $mock->shouldReceive('height')->andReturn('200')->once(); - $mock->shouldReceive('resize')->with(100, 100, $this->callback)->andReturn($mock)->once(); + $mock->shouldReceive('resize')->with(100, 100)->andReturn($mock)->once(); }); $this->assertInstanceOf( @@ -152,9 +152,9 @@ public function testRunResize() $mock->shouldReceive('width')->andReturn(100)->times(4); $mock->shouldReceive('height')->andReturn(100)->times(4); $mock->shouldReceive('crop')->andReturn($mock)->once(); - $mock->shouldReceive('resize')->with(100, 100, $this->callback)->andReturn($mock)->times(5); + $mock->shouldReceive('resize')->with(100, 100)->andReturn($mock)->times(5); $mock->shouldReceive('resize')->with(100, 100)->andReturn($mock)->once(); - $mock->shouldReceive('resizeCanvas')->with(100, 100, 'center')->andReturn($mock)->times(2); + $mock->shouldReceive('resizeCanvas')->with(100, 100, 'ffffff', 'center')->andReturn($mock)->times(2); }); $this->assertInstanceOf( @@ -196,7 +196,7 @@ public function testRunResize() public function testRunContainResize() { $image = Mockery::mock(ImageInterface::class, function ($mock) { - $mock->shouldReceive('resize')->with(100, 100, $this->callback)->andReturn($mock)->once(); + $mock->shouldReceive('resize')->with(100, 100)->andReturn($mock)->once(); }); $this->assertInstanceOf( @@ -208,8 +208,8 @@ public function testRunContainResize() public function testRunFillResize() { $image = Mockery::mock(ImageInterface::class, function ($mock) { - $mock->shouldReceive('resize')->with(100, 100, $this->callback)->andReturn($mock)->once(); - $mock->shouldReceive('resizeCanvas')->with(100, 100, 'center')->andReturn($mock)->once(); + $mock->shouldReceive('resize')->with(100, 100)->andReturn($mock)->once(); + $mock->shouldReceive('resizeCanvas')->with(100, 100, 'ffffff', 'center')->andReturn($mock)->once(); }); $this->assertInstanceOf( @@ -221,7 +221,7 @@ public function testRunFillResize() public function testRunMaxResize() { $image = Mockery::mock(ImageInterface::class, function ($mock) { - $mock->shouldReceive('resize')->with(100, 100, $this->callback)->andReturn($mock)->once(); + $mock->shouldReceive('resize')->with(100, 100)->andReturn($mock)->once(); }); $this->assertInstanceOf( @@ -247,7 +247,7 @@ public function testRunCropResize() $image = Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('width')->andReturn(100)->times(4); $mock->shouldReceive('height')->andReturn(100)->times(4); - $mock->shouldReceive('resize')->with(100, 100, $this->callback)->andReturn($mock)->once(); + $mock->shouldReceive('resize')->with(100, 100)->andReturn($mock)->once(); $mock->shouldReceive('crop')->with(100, 100, 0, 0)->andReturn($mock)->once(); }); From 59eba7d43ab8706a78b4de421e49192f9dbcac20 Mon Sep 17 00:00:00 2001 From: Konnng Date: Wed, 24 Jan 2024 10:54:00 -0300 Subject: [PATCH 30/64] fix Orientation manipulator --- src/Manipulators/Orientation.php | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/Manipulators/Orientation.php b/src/Manipulators/Orientation.php index 30dcfa42..5dbd2555 100644 --- a/src/Manipulators/Orientation.php +++ b/src/Manipulators/Orientation.php @@ -20,8 +20,32 @@ public function run(ImageInterface $image): ImageInterface { $orientation = $this->getOrientation(); - if ('auto' === $orientation) { - return $image->orientate(); + if ('auto' === $orientation && $image->exif('Orientation')) { + switch ($image->exif('Orientation')) { + case 2: + $image->flip(); + break; + case 3: + $image->rotate(180); + break; + case 4: + $image->rotate(180)->flip(); + break; + case 5: + $image->rotate(270)->flip(); + break; + case 6: + $image->rotate(270); + break; + case 7: + $image->rotate(90)->flip(); + break; + case 8: + $image->rotate(90); + break; + } + + return $image; } return $image->rotate((float) $orientation); From aeb60106cd59b7fc81fb11784002688987285c2e Mon Sep 17 00:00:00 2001 From: Art4 Date: Wed, 24 Jan 2024 15:10:16 +0100 Subject: [PATCH 31/64] Fix Api tests --- tests/Api/ApiTest.php | 11 ++++++----- tests/files/red-pixel.png | Bin 0 -> 119 bytes 2 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 tests/files/red-pixel.png diff --git a/tests/Api/ApiTest.php b/tests/Api/ApiTest.php index dd8250ad..de239be7 100644 --- a/tests/Api/ApiTest.php +++ b/tests/Api/ApiTest.php @@ -5,6 +5,7 @@ use Intervention\Image\ImageManager; use Intervention\Image\Interfaces\ImageInterface; use InvalidArgumentException; +use League\Glide\Manipulators\ManipulatorInterface; use Mockery; use PHPUnit\Framework\TestCase; @@ -24,7 +25,7 @@ public function tearDown(): void public function testCreateInstance() { - $this->assertInstanceOf('League\Glide\Api\Api', $this->api); + $this->assertInstanceOf(Api::class, $this->api); } public function testSetImageManager() @@ -40,9 +41,9 @@ public function testGetImageManager() public function testSetManipulators() { - $this->api->setManipulators([Mockery::mock('League\Glide\Manipulators\ManipulatorInterface')]); + $this->api->setManipulators([Mockery::mock(ManipulatorInterface::class)]); $manipulators = $this->api->getManipulators(); - $this->assertInstanceOf('League\Glide\Manipulators\ManipulatorInterface', $manipulators[0]); + $this->assertInstanceOf(ManipulatorInterface::class, $manipulators[0]); } public function testSetInvalidManipulator() @@ -66,13 +67,13 @@ public function testRun() $manager = ImageManager::gd(); - $manipulator = Mockery::mock('League\Glide\Manipulators\ManipulatorInterface', function ($mock) use ($image) { + $manipulator = Mockery::mock(ManipulatorInterface::class, function ($mock) use ($image) { $mock->shouldReceive('setParams')->with([]); $mock->shouldReceive('run')->andReturn($image); }); $api = new Api($manager, [$manipulator]); - $this->assertEquals('encoded', $api->run('source', [])); + $this->assertEquals('encoded', $api->run(dirname(__FILE__, 2) . '/files/red-pixel.png', [])); } } diff --git a/tests/files/red-pixel.png b/tests/files/red-pixel.png new file mode 100644 index 0000000000000000000000000000000000000000..abda018027a5b626a3e97c5dc50d26c7f97d354e GIT binary patch literal 119 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx1SBVv2j2s6ii6yp7}lMWc?smOq&xaLGB9lH z=l+w(3gmMZctjR6Fz_7)VaDV6D^h@hJf1F&Arj%q721oL7?{-=^+dDxfiyFCy85}S Ib4q9e0H4 Date: Wed, 24 Jan 2024 15:15:45 +0100 Subject: [PATCH 32/64] Fix code style with php-cs-fixer --- src/Api/Api.php | 3 +- src/Filesystem/FileNotFoundException.php | 4 +- src/Filesystem/FilesystemException.php | 4 +- src/Manipulators/Border.php | 24 +++---- src/Manipulators/Crop.php | 24 +++---- src/Manipulators/Helpers/Color.php | 8 +-- src/Manipulators/Helpers/Dimension.php | 2 +- src/Manipulators/Size.php | 42 ++++++------ src/Manipulators/Watermark.php | 4 +- src/Responses/PsrResponseFactory.php | 7 +- src/Server.php | 22 +++--- src/ServerFactory.php | 9 ++- src/Signatures/Signature.php | 4 +- src/Signatures/SignatureException.php | 4 +- src/Urls/UrlBuilder.php | 3 +- tests/Api/ApiTest.php | 16 ++--- tests/Manipulators/BackgroundTest.php | 11 ++- tests/Manipulators/BlurTest.php | 5 +- tests/Manipulators/BorderTest.php | 19 +++--- tests/Manipulators/BrightnessTest.php | 5 +- tests/Manipulators/ContrastTest.php | 5 +- tests/Manipulators/CropTest.php | 5 +- tests/Manipulators/EncodeTest.php | 7 +- tests/Manipulators/FilterTest.php | 9 ++- tests/Manipulators/FlipTest.php | 5 +- tests/Manipulators/GammaTest.php | 5 +- tests/Manipulators/Helpers/DimensionTest.php | 5 +- tests/Manipulators/OrientationTest.php | 5 +- tests/Manipulators/PixelateTest.php | 5 +- tests/Manipulators/SharpenTest.php | 5 +- tests/Manipulators/SizeTest.php | 29 ++++---- tests/Manipulators/WatermarkTest.php | 31 ++++----- tests/Responses/PsrResponseFactoryTest.php | 9 ++- tests/ServerFactoryTest.php | 26 ++++--- tests/ServerTest.php | 72 ++++++++++---------- 35 files changed, 204 insertions(+), 239 deletions(-) diff --git a/src/Api/Api.php b/src/Api/Api.php index 7b0bcea4..09aff921 100644 --- a/src/Api/Api.php +++ b/src/Api/Api.php @@ -3,7 +3,6 @@ namespace League\Glide\Api; use Intervention\Image\ImageManager; -use InvalidArgumentException; use League\Glide\Manipulators\ManipulatorInterface; class Api implements ApiInterface @@ -67,7 +66,7 @@ public function setManipulators(array $manipulators) { foreach ($manipulators as $manipulator) { if (!($manipulator instanceof ManipulatorInterface)) { - throw new InvalidArgumentException('Not a valid manipulator.'); + throw new \InvalidArgumentException('Not a valid manipulator.'); } } diff --git a/src/Filesystem/FileNotFoundException.php b/src/Filesystem/FileNotFoundException.php index acd25c05..cc0a3598 100644 --- a/src/Filesystem/FileNotFoundException.php +++ b/src/Filesystem/FileNotFoundException.php @@ -2,8 +2,6 @@ namespace League\Glide\Filesystem; -use Exception; - -class FileNotFoundException extends Exception +class FileNotFoundException extends \Exception { } diff --git a/src/Filesystem/FilesystemException.php b/src/Filesystem/FilesystemException.php index df6cbd6c..6826f82a 100644 --- a/src/Filesystem/FilesystemException.php +++ b/src/Filesystem/FilesystemException.php @@ -2,8 +2,6 @@ namespace League\Glide\Filesystem; -use Exception; - -class FilesystemException extends Exception +class FilesystemException extends \Exception { } diff --git a/src/Manipulators/Border.php b/src/Manipulators/Border.php index e87e132f..697014af 100644 --- a/src/Manipulators/Border.php +++ b/src/Manipulators/Border.php @@ -71,9 +71,9 @@ public function getBorder(ImageInterface $image): ?array /** * Get border width. * - * @param ImageInterface $image The source image. - * @param float $dpr The device pixel ratio. - * @param string $width The border width. + * @param ImageInterface $image The source image. + * @param float $dpr The device pixel ratio. + * @param string $width The border width. * * @return float|null The resolved border width. */ @@ -131,9 +131,9 @@ public function getDpr() /** * Run the overlay border method. * - * @param ImageInterface $image The source image. - * @param float $width The border width. - * @param string $color The border color. + * @param ImageInterface $image The source image. + * @param float $width The border width. + * @param string $color The border color. * * @return ImageInterface The manipulated image. */ @@ -153,9 +153,9 @@ function ($draw) use ($width, $color) { /** * Run the shrink border method. * - * @param ImageInterface $image The source image. - * @param float $width The border width. - * @param string $color The border color. + * @param ImageInterface $image The source image. + * @param float $width The border width. + * @param string $color The border color. * * @return ImageInterface The manipulated image. */ @@ -178,9 +178,9 @@ public function runShrink(ImageInterface $image, $width, $color): ImageInterface /** * Run the expand border method. * - * @param ImageInterface $image The source image. - * @param float $width The border width. - * @param string $color The border color. + * @param ImageInterface $image The source image. + * @param float $width The border width. + * @param string $color The border color. * * @return ImageInterface The manipulated image. */ diff --git a/src/Manipulators/Crop.php b/src/Manipulators/Crop.php index 6770a3ca..12ebcbe0 100644 --- a/src/Manipulators/Crop.php +++ b/src/Manipulators/Crop.php @@ -51,17 +51,17 @@ public function getCoordinates(ImageInterface $image): ?array $coordinates = explode(',', $this->crop); - if (4 !== count($coordinates) or - (!is_numeric($coordinates[0])) or - (!is_numeric($coordinates[1])) or - (!is_numeric($coordinates[2])) or - (!is_numeric($coordinates[3])) or - ($coordinates[0] <= 0) or - ($coordinates[1] <= 0) or - ($coordinates[2] < 0) or - ($coordinates[3] < 0) or - ($coordinates[2] >= $image->width()) or - ($coordinates[3] >= $image->height())) { + if (4 !== count($coordinates) + or (!is_numeric($coordinates[0])) + or (!is_numeric($coordinates[1])) + or (!is_numeric($coordinates[2])) + or (!is_numeric($coordinates[3])) + or ($coordinates[0] <= 0) + or ($coordinates[1] <= 0) + or ($coordinates[2] < 0) + or ($coordinates[3] < 0) + or ($coordinates[2] >= $image->width()) + or ($coordinates[3] >= $image->height())) { return null; } @@ -77,7 +77,7 @@ public function getCoordinates(ImageInterface $image): ?array * Limit coordinates to image boundaries. * * @param ImageInterface $image The source image. - * @param int[] $coordinates The coordinates. + * @param int[] $coordinates The coordinates. * * @return int[] The limited coordinates. */ diff --git a/src/Manipulators/Helpers/Color.php b/src/Manipulators/Helpers/Color.php index 4b77e36a..b401a679 100644 --- a/src/Manipulators/Helpers/Color.php +++ b/src/Manipulators/Helpers/Color.php @@ -7,22 +7,22 @@ class Color /** * 3 digit color code expression. */ - const SHORT_RGB = '/^[0-9a-f]{3}$/i'; + public const SHORT_RGB = '/^[0-9a-f]{3}$/i'; /** * 4 digit color code expression. */ - const SHORT_ARGB = '/^[0-9]{1}[0-9a-f]{3}$/i'; + public const SHORT_ARGB = '/^[0-9]{1}[0-9a-f]{3}$/i'; /** * 6 digit color code expression. */ - const LONG_RGB = '/^[0-9a-f]{6}$/i'; + public const LONG_RGB = '/^[0-9a-f]{6}$/i'; /** * 8 digit color code expression. */ - const LONG_ARGB = '/^[0-9]{2}[0-9a-f]{6}$/i'; + public const LONG_ARGB = '/^[0-9]{2}[0-9a-f]{6}$/i'; /** * The red value. diff --git a/src/Manipulators/Helpers/Dimension.php b/src/Manipulators/Helpers/Dimension.php index 5614832e..e7502aee 100644 --- a/src/Manipulators/Helpers/Dimension.php +++ b/src/Manipulators/Helpers/Dimension.php @@ -24,7 +24,7 @@ class Dimension * Create dimension helper instance. * * @param ImageInterface $image The source image. - * @param float $dpr The device pixel ratio. + * @param float $dpr The device pixel ratio. */ public function __construct(ImageInterface $image, $dpr = 1) { diff --git a/src/Manipulators/Size.php b/src/Manipulators/Size.php index ccba4ad4..c6c78f9e 100644 --- a/src/Manipulators/Size.php +++ b/src/Manipulators/Size.php @@ -157,8 +157,8 @@ public function getDpr() * Resolve missing image dimensions. * * @param ImageInterface $image The source image. - * @param int|null $width The image width. - * @param int|null $height The image height. + * @param int|null $width The image width. + * @param int|null $height The image height. * * @return int[] The resolved width and height. */ @@ -232,9 +232,9 @@ public function limitImageSize($width, $height) * Perform resize image manipulation. * * @param ImageInterface $image The source image. - * @param string $fit The fit. - * @param int $width The width. - * @param int $height The height. + * @param string $fit The fit. + * @param int $width The width. + * @param int $height The height. * * @return ImageInterface The manipulated image. */ @@ -271,8 +271,8 @@ public function runResize(ImageInterface $image, $fit, $width, $height): ImageIn * Perform contain resize image manipulation. * * @param ImageInterface $image The source image. - * @param int $width The width. - * @param int $height The height. + * @param int $width The width. + * @param int $height The height. * * @return ImageInterface The manipulated image. */ @@ -285,8 +285,8 @@ public function runContainResize(ImageInterface $image, $width, $height): ImageI * Perform max resize image manipulation. * * @param ImageInterface $image The source image. - * @param int $width The width. - * @param int $height The height. + * @param int $width The width. + * @param int $height The height. * * @return ImageInterface The manipulated image. */ @@ -299,8 +299,8 @@ public function runMaxResize(ImageInterface $image, $width, $height): ImageInter * Perform fill resize image manipulation. * * @param ImageInterface $image The source image. - * @param int $width The width. - * @param int $height The height. + * @param int $width The width. + * @param int $height The height. * * @return ImageInterface The manipulated image. */ @@ -315,8 +315,8 @@ public function runFillResize(ImageInterface $image, $width, $height): ImageInte * Perform fill-max resize image manipulation. * * @param ImageInterface $image The source image. - * @param int $width The width. - * @param int $height The height. + * @param int $width The width. + * @param int $height The height. * * @return ImageInterface The manipulated image. */ @@ -331,8 +331,8 @@ public function runFillMaxResize(ImageInterface $image, $width, $height): ImageI * Perform stretch resize image manipulation. * * @param ImageInterface $image The source image. - * @param int $width The width. - * @param int $height The height. + * @param int $width The width. + * @param int $height The height. * * @return ImageInterface The manipulated image. */ @@ -345,8 +345,8 @@ public function runStretchResize(ImageInterface $image, $width, $height): ImageI * Perform crop resize image manipulation. * * @param ImageInterface $image The source image. - * @param int $width The width. - * @param int $height The height. + * @param int $width The width. + * @param int $height The height. * * @return ImageInterface The manipulated image. */ @@ -367,8 +367,8 @@ public function runCropResize(ImageInterface $image, $width, $height): ImageInte * Resolve the crop resize dimensions. * * @param ImageInterface $image The source image. - * @param int $width The width. - * @param int $height The height. + * @param int $width The width. + * @param int $height The height. * * @return array The resize dimensions. */ @@ -385,8 +385,8 @@ public function resolveCropResizeDimensions(ImageInterface $image, $width, $heig * Resolve the crop offset. * * @param ImageInterface $image The source image. - * @param int $width The width. - * @param int $height The height. + * @param int $width The width. + * @param int $height The height. * * @return array The crop offset. */ diff --git a/src/Manipulators/Watermark.php b/src/Manipulators/Watermark.php index 1109933e..82f180e8 100644 --- a/src/Manipulators/Watermark.php +++ b/src/Manipulators/Watermark.php @@ -173,8 +173,8 @@ public function getImage(ImageInterface $image): ?ImageInterface /** * Get a dimension. * - * @param ImageInterface $image The source image. - * @param string $field The requested field. + * @param ImageInterface $image The source image. + * @param string $field The requested field. * * @return float|null The dimension. */ diff --git a/src/Responses/PsrResponseFactory.php b/src/Responses/PsrResponseFactory.php index cfd2637b..cff5a1c2 100644 --- a/src/Responses/PsrResponseFactory.php +++ b/src/Responses/PsrResponseFactory.php @@ -2,7 +2,6 @@ namespace League\Glide\Responses; -use Closure; use League\Flysystem\FilesystemOperator; use Psr\Http\Message\ResponseInterface; @@ -18,7 +17,7 @@ class PsrResponseFactory implements ResponseFactoryInterface /** * Callback to create stream. * - * @var Closure + * @var \Closure */ protected $streamCallback; @@ -26,9 +25,9 @@ class PsrResponseFactory implements ResponseFactoryInterface * Create PsrResponseFactory instance. * * @param ResponseInterface $response Base response object. - * @param Closure $streamCallback Callback to create stream. + * @param \Closure $streamCallback Callback to create stream. */ - public function __construct(ResponseInterface $response, Closure $streamCallback) + public function __construct(ResponseInterface $response, \Closure $streamCallback) { $this->response = $response; $this->streamCallback = $streamCallback; diff --git a/src/Server.php b/src/Server.php index fb77046e..0e30a109 100644 --- a/src/Server.php +++ b/src/Server.php @@ -2,8 +2,6 @@ namespace League\Glide; -use Closure; -use InvalidArgumentException; use League\Flysystem\FilesystemException as FilesystemV2Exception; use League\Flysystem\FilesystemOperator; use League\Glide\Api\ApiInterface; @@ -292,12 +290,12 @@ public function getTempDir() * * @return void * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException */ public function setTempDir($tempDir) { if (!$tempDir || !is_dir($tempDir)) { - throw new InvalidArgumentException(sprintf('Invalid temp dir provided: "%s" does not exist.', $tempDir)); + throw new \InvalidArgumentException(sprintf('Invalid temp dir provided: "%s" does not exist.', $tempDir)); } $this->tempDir = rtrim($tempDir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; @@ -352,7 +350,7 @@ public function getCacheWithFileExtensions() * * @param \Closure|null $cachePathCallable The custom cache path callable. It receives the same arguments as @see getCachePath */ - public function setCachePathCallable(?Closure $cachePathCallable) + public function setCachePathCallable(?\Closure $cachePathCallable) { $this->cachePathCallable = $cachePathCallable; } @@ -379,7 +377,7 @@ public function getCachePath($path, array $params = []) { $customCallable = $this->getCachePathCallable(); if (null !== $customCallable) { - $boundCallable = Closure::bind($customCallable, $this, static::class); + $boundCallable = \Closure::bind($customCallable, $this, static::class); return $boundCallable($path, $params); } @@ -442,7 +440,7 @@ public function cacheFileExists($path, array $params) public function deleteCache($path) { if (!$this->groupCacheInFolders) { - throw new InvalidArgumentException('Deleting cached image manipulations is not possible when grouping cache into folders is disabled.'); + throw new \InvalidArgumentException('Deleting cached image manipulations is not possible when grouping cache into folders is disabled.'); } try { @@ -574,12 +572,12 @@ public function getResponseFactory() * * @return mixed Image response. * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException */ public function getImageResponse($path, array $params) { if (is_null($this->responseFactory)) { - throw new InvalidArgumentException('Unable to get image response, no response factory defined.'); + throw new \InvalidArgumentException('Unable to get image response, no response factory defined.'); } $path = $this->makeImage($path, $params); @@ -616,9 +614,9 @@ public function getImageAsBase64($path, array $params) * @param string $path Image path. * @param array $params Image manipulation params. * - * @throws InvalidArgumentException - * * @return void + * + * @throws \InvalidArgumentException */ public function outputImage($path, array $params) { @@ -627,7 +625,7 @@ public function outputImage($path, array $params) try { header('Content-Type:'.$this->cache->mimeType($path)); header('Content-Length:'.$this->cache->fileSize($path)); - header('Cache-Control:'.'max-age=31536000, public'); + header('Cache-Control:max-age=31536000, public'); header('Expires:'.date_create('+1 years')->format('D, d M Y H:i:s').' GMT'); $stream = $this->cache->readStream($path); diff --git a/src/ServerFactory.php b/src/ServerFactory.php index 0faa3eb5..2ee849e0 100644 --- a/src/ServerFactory.php +++ b/src/ServerFactory.php @@ -3,7 +3,6 @@ namespace League\Glide; use Intervention\Image\ImageManager; -use InvalidArgumentException; use League\Flysystem\Filesystem; use League\Flysystem\FilesystemOperator; use League\Flysystem\Local\LocalFilesystemAdapter; @@ -82,7 +81,7 @@ public function getServer() public function getSource() { if (!isset($this->config['source'])) { - throw new InvalidArgumentException('A "source" file system must be set.'); + throw new \InvalidArgumentException('A "source" file system must be set.'); } if (is_string($this->config['source'])) { @@ -114,7 +113,7 @@ public function getSourcePathPrefix() public function getCache() { if (!isset($this->config['cache'])) { - throw new InvalidArgumentException('A "cache" file system must be set.'); + throw new \InvalidArgumentException('A "cache" file system must be set.'); } if (is_string($this->config['cache'])) { @@ -246,9 +245,9 @@ public function getImageManager() $driver = $this->config['driver']; } - if ($driver === 'gd') { + if ('gd' === $driver) { $manager = ImageManager::gd(); - } else if ($driver === 'imagick') { + } elseif ('imagick' === $driver) { $manager = ImageManager::imagick(); } else { $manager = ImageManager::withDriver($driver); diff --git a/src/Signatures/Signature.php b/src/Signatures/Signature.php index 82200a37..44bdec78 100644 --- a/src/Signatures/Signature.php +++ b/src/Signatures/Signature.php @@ -40,9 +40,9 @@ public function addSignature($path, array $params) * @param string $path The resource path. * @param array $params The manipulation params. * - * @throws SignatureException - * * @return void + * + * @throws SignatureException */ public function validateRequest($path, array $params) { diff --git a/src/Signatures/SignatureException.php b/src/Signatures/SignatureException.php index ba2f4c2c..76722e0f 100644 --- a/src/Signatures/SignatureException.php +++ b/src/Signatures/SignatureException.php @@ -2,8 +2,6 @@ namespace League\Glide\Signatures; -use Exception; - -class SignatureException extends Exception +class SignatureException extends \Exception { } diff --git a/src/Urls/UrlBuilder.php b/src/Urls/UrlBuilder.php index 5cc2d357..ee1fffd4 100644 --- a/src/Urls/UrlBuilder.php +++ b/src/Urls/UrlBuilder.php @@ -2,7 +2,6 @@ namespace League\Glide\Urls; -use InvalidArgumentException; use League\Glide\Signatures\SignatureInterface; class UrlBuilder @@ -82,7 +81,7 @@ public function getUrl($path, array $params = []) $parts = parse_url($this->baseUrl.'/'.trim($path, '/')); if (false === $parts) { - throw new InvalidArgumentException('Not a valid path.'); + throw new \InvalidArgumentException('Not a valid path.'); } $parts['path'] = '/'.trim($parts['path'], '/'); diff --git a/tests/Api/ApiTest.php b/tests/Api/ApiTest.php index de239be7..6785bf87 100644 --- a/tests/Api/ApiTest.php +++ b/tests/Api/ApiTest.php @@ -4,9 +4,7 @@ use Intervention\Image\ImageManager; use Intervention\Image\Interfaces\ImageInterface; -use InvalidArgumentException; use League\Glide\Manipulators\ManipulatorInterface; -use Mockery; use PHPUnit\Framework\TestCase; class ApiTest extends TestCase @@ -20,7 +18,7 @@ public function setUp(): void public function tearDown(): void { - Mockery::close(); + \Mockery::close(); } public function testCreateInstance() @@ -41,17 +39,17 @@ public function testGetImageManager() public function testSetManipulators() { - $this->api->setManipulators([Mockery::mock(ManipulatorInterface::class)]); + $this->api->setManipulators([\Mockery::mock(ManipulatorInterface::class)]); $manipulators = $this->api->getManipulators(); $this->assertInstanceOf(ManipulatorInterface::class, $manipulators[0]); } public function testSetInvalidManipulator() { - $this->expectException(InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Not a valid manipulator.'); - $this->api->setManipulators([new \StdClass()]); + $this->api->setManipulators([new \stdClass()]); } public function testGetManipulators() @@ -61,19 +59,19 @@ public function testGetManipulators() public function testRun() { - $image = Mockery::mock(ImageInterface::class, function ($mock) { + $image = \Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('getEncoded')->andReturn('encoded'); }); $manager = ImageManager::gd(); - $manipulator = Mockery::mock(ManipulatorInterface::class, function ($mock) use ($image) { + $manipulator = \Mockery::mock(ManipulatorInterface::class, function ($mock) use ($image) { $mock->shouldReceive('setParams')->with([]); $mock->shouldReceive('run')->andReturn($image); }); $api = new Api($manager, [$manipulator]); - $this->assertEquals('encoded', $api->run(dirname(__FILE__, 2) . '/files/red-pixel.png', [])); + $this->assertEquals('encoded', $api->run(dirname(__FILE__, 2).'/files/red-pixel.png', [])); } } diff --git a/tests/Manipulators/BackgroundTest.php b/tests/Manipulators/BackgroundTest.php index 2f7f7dcc..d049a114 100644 --- a/tests/Manipulators/BackgroundTest.php +++ b/tests/Manipulators/BackgroundTest.php @@ -4,7 +4,6 @@ use Intervention\Image\Interfaces\DriverInterface; use Intervention\Image\Interfaces\ImageInterface; -use Mockery; use PHPUnit\Framework\TestCase; class BackgroundTest extends TestCase @@ -13,7 +12,7 @@ class BackgroundTest extends TestCase public function tearDown(): void { - Mockery::close(); + \Mockery::close(); } public function testCreateInstance() @@ -23,12 +22,12 @@ public function testCreateInstance() public function testRun() { - $image = Mockery::mock(ImageInterface::class, function ($mock) { + $image = \Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('width')->andReturn(100)->once(); $mock->shouldReceive('height')->andReturn(100)->once(); - $mock->shouldReceive('driver')->andReturn(Mockery::mock(DriverInterface::class, function ($mock) { - $mock->shouldReceive('createImage')->with(100, 100)->andReturn(Mockery::mock(ImageInterface::class, function ($mock) { - $mock->shouldReceive('fill')->with('rgba(0, 0, 0, 1)')->andReturn(Mockery::mock(ImageInterface::class, function ($mock) { + $mock->shouldReceive('driver')->andReturn(\Mockery::mock(DriverInterface::class, function ($mock) { + $mock->shouldReceive('createImage')->with(100, 100)->andReturn(\Mockery::mock(ImageInterface::class, function ($mock) { + $mock->shouldReceive('fill')->with('rgba(0, 0, 0, 1)')->andReturn(\Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('place')->andReturn($mock)->once(); }))->once(); }))->once(); diff --git a/tests/Manipulators/BlurTest.php b/tests/Manipulators/BlurTest.php index 46c65b98..f41543e3 100644 --- a/tests/Manipulators/BlurTest.php +++ b/tests/Manipulators/BlurTest.php @@ -3,7 +3,6 @@ namespace League\Glide\Manipulators; use Intervention\Image\Interfaces\ImageInterface; -use Mockery; use PHPUnit\Framework\TestCase; class BlurTest extends TestCase @@ -17,7 +16,7 @@ public function setUp(): void public function tearDown(): void { - Mockery::close(); + \Mockery::close(); } public function testCreateInstance() @@ -27,7 +26,7 @@ public function testCreateInstance() public function testRun() { - $image = Mockery::mock(ImageInterface::class, function ($mock) { + $image = \Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('blur')->with('10')->once(); }); diff --git a/tests/Manipulators/BorderTest.php b/tests/Manipulators/BorderTest.php index 5438ba64..9689df63 100644 --- a/tests/Manipulators/BorderTest.php +++ b/tests/Manipulators/BorderTest.php @@ -3,7 +3,6 @@ namespace League\Glide\Manipulators; use Intervention\Image\Interfaces\ImageInterface; -use Mockery; use PHPUnit\Framework\TestCase; class BorderTest extends TestCase @@ -12,7 +11,7 @@ class BorderTest extends TestCase public function tearDown(): void { - Mockery::close(); + \Mockery::close(); } public function testCreateInstance() @@ -22,7 +21,7 @@ public function testCreateInstance() public function testGetBorder() { - $image = Mockery::mock(ImageInterface::class); + $image = \Mockery::mock(ImageInterface::class); $border = new Border(); @@ -36,7 +35,7 @@ public function testGetBorder() public function testGetInvalidBorder() { - $image = Mockery::mock(ImageInterface::class); + $image = \Mockery::mock(ImageInterface::class); $border = new Border(); @@ -47,7 +46,7 @@ public function testGetInvalidBorder() public function testGetWidth() { - $image = Mockery::mock(ImageInterface::class); + $image = \Mockery::mock(ImageInterface::class); $border = new Border(); @@ -83,7 +82,7 @@ public function testGetDpr() public function testRunWithNoBorder() { - $image = Mockery::mock(ImageInterface::class); + $image = \Mockery::mock(ImageInterface::class); $border = new Border(); @@ -92,10 +91,10 @@ public function testRunWithNoBorder() public function testRunOverlay() { - $image = Mockery::mock(ImageInterface::class, function ($mock) { + $image = \Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('width')->andReturn(100)->once(); $mock->shouldReceive('height')->andReturn(100)->once(); - $mock->shouldReceive('rectangle')->with(5, 5, 95, 95, Mockery::on(function ($closure) { + $mock->shouldReceive('rectangle')->with(5, 5, 95, 95, \Mockery::on(function ($closure) { return true; }))->andReturn($mock)->once(); }); @@ -108,7 +107,7 @@ public function testRunOverlay() public function testRunShrink() { - $image = Mockery::mock(ImageInterface::class, function ($mock) { + $image = \Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('width')->andReturn(100)->once(); $mock->shouldReceive('height')->andReturn(100)->once(); $mock->shouldReceive('resize')->with(80, 80)->andReturn($mock)->once(); @@ -123,7 +122,7 @@ public function testRunShrink() public function testRunExpand() { - $image = Mockery::mock(ImageInterface::class, function ($mock) { + $image = \Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('resizeCanvas')->with(20, 20, 'center', true, 'rgba(0, 0, 0, 0.5)')->andReturn($mock)->once(); }); diff --git a/tests/Manipulators/BrightnessTest.php b/tests/Manipulators/BrightnessTest.php index 11282404..5f0a657f 100644 --- a/tests/Manipulators/BrightnessTest.php +++ b/tests/Manipulators/BrightnessTest.php @@ -3,7 +3,6 @@ namespace League\Glide\Manipulators; use Intervention\Image\Interfaces\ImageInterface; -use Mockery; use PHPUnit\Framework\TestCase; class BrightnessTest extends TestCase @@ -17,7 +16,7 @@ public function setUp(): void public function tearDown(): void { - Mockery::close(); + \Mockery::close(); } public function testCreateInstance() @@ -27,7 +26,7 @@ public function testCreateInstance() public function testRun() { - $image = Mockery::mock(ImageInterface::class, function ($mock) { + $image = \Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('brightness')->with('50')->once(); }); diff --git a/tests/Manipulators/ContrastTest.php b/tests/Manipulators/ContrastTest.php index 7a1e588f..a814bd07 100644 --- a/tests/Manipulators/ContrastTest.php +++ b/tests/Manipulators/ContrastTest.php @@ -3,7 +3,6 @@ namespace League\Glide\Manipulators; use Intervention\Image\Interfaces\ImageInterface; -use Mockery; use PHPUnit\Framework\TestCase; class ContrastTest extends TestCase @@ -17,7 +16,7 @@ public function setUp(): void public function tearDown(): void { - Mockery::close(); + \Mockery::close(); } public function testCreateInstance() @@ -27,7 +26,7 @@ public function testCreateInstance() public function testRun() { - $image = Mockery::mock(ImageInterface::class, function ($mock) { + $image = \Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('contrast')->with('50')->once(); }); diff --git a/tests/Manipulators/CropTest.php b/tests/Manipulators/CropTest.php index fded9c77..627ad007 100644 --- a/tests/Manipulators/CropTest.php +++ b/tests/Manipulators/CropTest.php @@ -3,7 +3,6 @@ namespace League\Glide\Manipulators; use Intervention\Image\Interfaces\ImageInterface; -use Mockery; use PHPUnit\Framework\TestCase; class CropTest extends TestCase @@ -14,7 +13,7 @@ class CropTest extends TestCase public function setUp(): void { $this->manipulator = new Crop(); - $this->image = Mockery::mock(ImageInterface::class, function ($mock) { + $this->image = \Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('width')->andReturn(100); $mock->shouldReceive('height')->andReturn(100); }); @@ -22,7 +21,7 @@ public function setUp(): void public function tearDown(): void { - Mockery::close(); + \Mockery::close(); } public function testCreateInstance() diff --git a/tests/Manipulators/EncodeTest.php b/tests/Manipulators/EncodeTest.php index 449c898f..d0b2d165 100644 --- a/tests/Manipulators/EncodeTest.php +++ b/tests/Manipulators/EncodeTest.php @@ -5,7 +5,6 @@ use Intervention\Image\Encoders\MediaTypeEncoder; use Intervention\Image\ImageManager; use Intervention\Image\Interfaces\ImageInterface; -use Mockery; use PHPUnit\Framework\TestCase; class EncodeTest extends TestCase @@ -38,7 +37,7 @@ public function setUp(): void public function tearDown(): void { - Mockery::close(); + \Mockery::close(); } public function testCreateInstance() @@ -90,7 +89,7 @@ public function testRun() public function testGetFormat() { - $image = Mockery::mock(ImageInterface::class, function ($mock) { + $image = \Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('mime')->andReturn('image/jpeg')->once(); $mock->shouldReceive('mime')->andReturn('image/png')->once(); $mock->shouldReceive('mime')->andReturn('image/gif')->once(); @@ -148,7 +147,7 @@ public function testWithImagick() ); } $manager = ImageManager::imagick(); - //These need to be recreated with the imagick driver selected in the manager + // These need to be recreated with the imagick driver selected in the manager $this->jpg = $manager->create(100, 100)->encode(new MediaTypeEncoder('image/jpeg')); $this->png = $manager->create(100, 100)->encode(new MediaTypeEncoder('image/png')); $this->gif = $manager->create(100, 100)->encode(new MediaTypeEncoder('image/gif')); diff --git a/tests/Manipulators/FilterTest.php b/tests/Manipulators/FilterTest.php index 0978f107..a49833e8 100644 --- a/tests/Manipulators/FilterTest.php +++ b/tests/Manipulators/FilterTest.php @@ -3,7 +3,6 @@ namespace League\Glide\Manipulators; use Intervention\Image\Interfaces\ImageInterface; -use Mockery; use PHPUnit\Framework\TestCase; class FilterTest extends TestCase @@ -17,7 +16,7 @@ public function setUp(): void public function tearDown(): void { - Mockery::close(); + \Mockery::close(); } public function testCreateInstance() @@ -27,7 +26,7 @@ public function testCreateInstance() public function testRun() { - $image = Mockery::mock(ImageInterface::class, function ($mock) { + $image = \Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('greyscale')->twice()->andReturn($mock) ->shouldReceive('brightness')->with(-10)->twice()->andReturn($mock) ->shouldReceive('contrast')->with(10)->twice()->andReturn($mock) @@ -52,7 +51,7 @@ public function testRun() public function testRunGreyscaleFilter() { - $image = Mockery::mock(ImageInterface::class, function ($mock) { + $image = \Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('greyscale')->andReturn($mock)->once(); }); @@ -64,7 +63,7 @@ public function testRunGreyscaleFilter() public function testRunSepiaFilter() { - $image = Mockery::mock(ImageInterface::class, function ($mock) { + $image = \Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('greyscale')->once()->andReturn($mock) ->shouldReceive('brightness')->with(-10)->twice()->andReturn($mock) ->shouldReceive('contrast')->with(10)->twice()->andReturn($mock) diff --git a/tests/Manipulators/FlipTest.php b/tests/Manipulators/FlipTest.php index 273f979e..e923cf8f 100644 --- a/tests/Manipulators/FlipTest.php +++ b/tests/Manipulators/FlipTest.php @@ -3,7 +3,6 @@ namespace League\Glide\Manipulators; use Intervention\Image\Interfaces\ImageInterface; -use Mockery; use PHPUnit\Framework\TestCase; class FlipTest extends TestCase @@ -17,7 +16,7 @@ public function setUp(): void public function tearDown(): void { - Mockery::close(); + \Mockery::close(); } public function testCreateInstance() @@ -27,7 +26,7 @@ public function testCreateInstance() public function testRun() { - $image = Mockery::mock(ImageInterface::class, function ($mock) { + $image = \Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('flip')->andReturn($mock)->with('h')->once(); $mock->shouldReceive('flip')->andReturn($mock)->with('v')->once(); }); diff --git a/tests/Manipulators/GammaTest.php b/tests/Manipulators/GammaTest.php index 3c8c6da0..a1907ccd 100644 --- a/tests/Manipulators/GammaTest.php +++ b/tests/Manipulators/GammaTest.php @@ -3,7 +3,6 @@ namespace League\Glide\Manipulators; use Intervention\Image\Interfaces\ImageInterface; -use Mockery; use PHPUnit\Framework\TestCase; class GammaTest extends TestCase @@ -17,7 +16,7 @@ public function setUp(): void public function tearDown(): void { - Mockery::close(); + \Mockery::close(); } public function testCreateInstance() @@ -27,7 +26,7 @@ public function testCreateInstance() public function testRun() { - $image = Mockery::mock(ImageInterface::class, function ($mock) { + $image = \Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('gamma')->with('1.5')->once(); }); diff --git a/tests/Manipulators/Helpers/DimensionTest.php b/tests/Manipulators/Helpers/DimensionTest.php index dba8645a..021fca68 100644 --- a/tests/Manipulators/Helpers/DimensionTest.php +++ b/tests/Manipulators/Helpers/DimensionTest.php @@ -3,7 +3,6 @@ namespace League\Glide\Manipulators\Helpers; use Intervention\Image\Interfaces\ImageInterface; -use Mockery; use PHPUnit\Framework\TestCase; class DimensionTest extends TestCase @@ -12,12 +11,12 @@ class DimensionTest extends TestCase public function setUp(): void { - $this->image = Mockery::mock(ImageInterface::class); + $this->image = \Mockery::mock(ImageInterface::class); } public function tearDown(): void { - Mockery::close(); + \Mockery::close(); } public function testPixels() diff --git a/tests/Manipulators/OrientationTest.php b/tests/Manipulators/OrientationTest.php index cbf8098f..18dc7039 100644 --- a/tests/Manipulators/OrientationTest.php +++ b/tests/Manipulators/OrientationTest.php @@ -3,7 +3,6 @@ namespace League\Glide\Manipulators; use Intervention\Image\Interfaces\ImageInterface; -use Mockery; use PHPUnit\Framework\TestCase; class OrientationTest extends TestCase @@ -17,7 +16,7 @@ public function setUp(): void public function tearDown(): void { - Mockery::close(); + \Mockery::close(); } public function testCreateInstance() @@ -27,7 +26,7 @@ public function testCreateInstance() public function testRun() { - $image = Mockery::mock(ImageInterface::class, function ($mock) { + $image = \Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('orientate')->andReturn($mock)->once(); $mock->shouldReceive('rotate')->andReturn($mock)->with('90')->once(); }); diff --git a/tests/Manipulators/PixelateTest.php b/tests/Manipulators/PixelateTest.php index 3067eb24..04abd105 100644 --- a/tests/Manipulators/PixelateTest.php +++ b/tests/Manipulators/PixelateTest.php @@ -3,7 +3,6 @@ namespace League\Glide\Manipulators; use Intervention\Image\Interfaces\ImageInterface; -use Mockery; use PHPUnit\Framework\TestCase; class PixelateTest extends TestCase @@ -17,7 +16,7 @@ public function setUp(): void public function tearDown(): void { - Mockery::close(); + \Mockery::close(); } public function testCreateInstance() @@ -27,7 +26,7 @@ public function testCreateInstance() public function testRun() { - $image = Mockery::mock(ImageInterface::class, function ($mock) { + $image = \Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('pixelate')->with('10')->once(); }); diff --git a/tests/Manipulators/SharpenTest.php b/tests/Manipulators/SharpenTest.php index b7d6608d..b6795120 100644 --- a/tests/Manipulators/SharpenTest.php +++ b/tests/Manipulators/SharpenTest.php @@ -3,7 +3,6 @@ namespace League\Glide\Manipulators; use Intervention\Image\Interfaces\ImageInterface; -use Mockery; use PHPUnit\Framework\TestCase; class SharpenTest extends TestCase @@ -17,7 +16,7 @@ public function setUp(): void public function tearDown(): void { - Mockery::close(); + \Mockery::close(); } public function testCreateInstance() @@ -27,7 +26,7 @@ public function testCreateInstance() public function testRun() { - $image = Mockery::mock(ImageInterface::class, function ($mock) { + $image = \Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('sharpen')->with('10')->once(); }); diff --git a/tests/Manipulators/SizeTest.php b/tests/Manipulators/SizeTest.php index edeaf9e6..c24cb4fd 100644 --- a/tests/Manipulators/SizeTest.php +++ b/tests/Manipulators/SizeTest.php @@ -3,7 +3,6 @@ namespace League\Glide\Manipulators; use Intervention\Image\Interfaces\ImageInterface; -use Mockery; use PHPUnit\Framework\TestCase; class SizeTest extends TestCase @@ -14,14 +13,14 @@ class SizeTest extends TestCase public function setUp(): void { $this->manipulator = new Size(); - $this->callback = Mockery::on(function () { + $this->callback = \Mockery::on(function () { return true; }); } public function tearDown(): void { - Mockery::close(); + \Mockery::close(); } public function testCreateInstance() @@ -42,7 +41,7 @@ public function testGetMaxImageSize() public function testRun() { - $image = Mockery::mock(ImageInterface::class, function ($mock) { + $image = \Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('width')->andReturn('200')->twice(); $mock->shouldReceive('height')->andReturn('200')->once(); $mock->shouldReceive('resize')->with(100, 100)->andReturn($mock)->once(); @@ -118,7 +117,7 @@ public function testGetDpr() public function testResolveMissingDimensions() { - $image = Mockery::mock(ImageInterface::class, function ($mock) { + $image = \Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('width')->andReturn(400); $mock->shouldReceive('height')->andReturn(200); }); @@ -130,7 +129,7 @@ public function testResolveMissingDimensions() public function testResolveMissingDimensionsWithOddDimensions() { - $image = Mockery::mock(ImageInterface::class, function ($mock) { + $image = \Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('width')->andReturn(1024); $mock->shouldReceive('height')->andReturn(553); }); @@ -148,7 +147,7 @@ public function testLimitImageSize() public function testRunResize() { - $image = Mockery::mock(ImageInterface::class, function ($mock) { + $image = \Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('width')->andReturn(100)->times(4); $mock->shouldReceive('height')->andReturn(100)->times(4); $mock->shouldReceive('crop')->andReturn($mock)->once(); @@ -195,7 +194,7 @@ public function testRunResize() public function testRunContainResize() { - $image = Mockery::mock(ImageInterface::class, function ($mock) { + $image = \Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('resize')->with(100, 100)->andReturn($mock)->once(); }); @@ -207,7 +206,7 @@ public function testRunContainResize() public function testRunFillResize() { - $image = Mockery::mock(ImageInterface::class, function ($mock) { + $image = \Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('resize')->with(100, 100)->andReturn($mock)->once(); $mock->shouldReceive('resizeCanvas')->with(100, 100, 'ffffff', 'center')->andReturn($mock)->once(); }); @@ -220,7 +219,7 @@ public function testRunFillResize() public function testRunMaxResize() { - $image = Mockery::mock(ImageInterface::class, function ($mock) { + $image = \Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('resize')->with(100, 100)->andReturn($mock)->once(); }); @@ -232,7 +231,7 @@ public function testRunMaxResize() public function testRunStretchResize() { - $image = Mockery::mock(ImageInterface::class, function ($mock) { + $image = \Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('resize')->with(100, 100)->andReturn($mock)->once(); }); @@ -244,7 +243,7 @@ public function testRunStretchResize() public function testRunCropResize() { - $image = Mockery::mock(ImageInterface::class, function ($mock) { + $image = \Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('width')->andReturn(100)->times(4); $mock->shouldReceive('height')->andReturn(100)->times(4); $mock->shouldReceive('resize')->with(100, 100)->andReturn($mock)->once(); @@ -259,7 +258,7 @@ public function testRunCropResize() public function testResizeDoesNotRunWhenNoParamsAreSet() { - $image = Mockery::mock(ImageInterface::class, function ($mock) { + $image = \Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('width')->andReturn(100)->twice(); $mock->shouldReceive('height')->andReturn(100)->twice(); $mock->shouldReceive('resize')->never(); @@ -273,7 +272,7 @@ public function testResizeDoesNotRunWhenNoParamsAreSet() public function testResizeDoesNotRunWhenSettingFitCropToCenterWithNoZoom() { - $image = Mockery::mock(ImageInterface::class, function ($mock) { + $image = \Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('width')->andReturn(100)->twice(); $mock->shouldReceive('height')->andReturn(100)->twice(); $mock->shouldReceive('resize')->never(); @@ -289,7 +288,7 @@ public function testResizeDoesNotRunWhenSettingFitCropToCenterWithNoZoom() public function testResizeDoesRunWhenDimensionsAreTheSameAndTheCropZoomIsNotDefaultOne() { - $image = Mockery::mock(ImageInterface::class, function ($mock) { + $image = \Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('width')->andReturn(100); $mock->shouldReceive('height')->andReturn(100); $mock->shouldReceive('resize')->once(); diff --git a/tests/Manipulators/WatermarkTest.php b/tests/Manipulators/WatermarkTest.php index c392eee0..4235066a 100644 --- a/tests/Manipulators/WatermarkTest.php +++ b/tests/Manipulators/WatermarkTest.php @@ -5,7 +5,6 @@ use Intervention\Image\Interfaces\DriverInterface; use Intervention\Image\Interfaces\ImageInterface; use League\Glide\Filesystem\FilesystemException; -use Mockery; use PHPUnit\Framework\TestCase; class WatermarkTest extends TestCase @@ -15,13 +14,13 @@ class WatermarkTest extends TestCase public function setUp(): void { $this->manipulator = new Watermark( - Mockery::mock('League\Flysystem\FilesystemOperator') + \Mockery::mock('League\Flysystem\FilesystemOperator') ); } public function tearDown(): void { - Mockery::close(); + \Mockery::close(); } public function testCreateInstance() @@ -31,7 +30,7 @@ public function testCreateInstance() public function testSetWatermarks() { - $this->manipulator->setWatermarks(Mockery::mock('League\Flysystem\FilesystemOperator')); + $this->manipulator->setWatermarks(\Mockery::mock('League\Flysystem\FilesystemOperator')); $this->assertInstanceOf('League\Flysystem\FilesystemOperator', $this->manipulator->getWatermarks()); } @@ -53,17 +52,17 @@ public function testGetWatermarksPathPrefix() public function testRun() { - $image = Mockery::mock(ImageInterface::class, function ($mock) { + $image = \Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('place')->once(); - $mock->shouldReceive('driver')->andReturn(Mockery::mock(DriverInterface::class, function ($mock) { - $mock->shouldReceive('handleInput')->with('content')->andReturn(Mockery::mock(ImageInterface::class, function ($mock) { + $mock->shouldReceive('driver')->andReturn(\Mockery::mock(DriverInterface::class, function ($mock) { + $mock->shouldReceive('handleInput')->with('content')->andReturn(\Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('width')->andReturn(0)->once(); $mock->shouldReceive('resize')->once(); }))->once(); }))->once(); }); - $this->manipulator->setWatermarks(Mockery::mock('League\Flysystem\FilesystemOperator', function ($watermarks) { + $this->manipulator->setWatermarks(\Mockery::mock('League\Flysystem\FilesystemOperator', function ($watermarks) { $watermarks->shouldReceive('fileExists')->with('image.jpg')->andReturn(true)->once(); $watermarks->shouldReceive('read')->with('image.jpg')->andReturn('content')->once(); })); @@ -98,13 +97,13 @@ public function testGetImage() $this->manipulator->setWatermarksPathPrefix('watermarks'); - $driver = Mockery::mock(DriverInterface::class); + $driver = \Mockery::mock(DriverInterface::class); $driver->shouldReceive('handleInput') ->with('content') - ->andReturn(Mockery::mock(ImageInterface::class)) + ->andReturn(\Mockery::mock(ImageInterface::class)) ->once(); - $image = Mockery::mock(ImageInterface::class); + $image = \Mockery::mock(ImageInterface::class); $image->shouldReceive('driver') ->andReturn($driver) ->once(); @@ -127,21 +126,21 @@ public function testGetImageWithUnreadableSource() ->andThrow('League\Flysystem\UnableToReadFile') ->once(); - $image = Mockery::mock(ImageInterface::class); + $image = \Mockery::mock(ImageInterface::class); $this->manipulator->setParams(['mark' => 'image.jpg'])->getImage($image); } public function testGetImageWithoutMarkParam() { - $image = Mockery::mock(ImageInterface::class); + $image = \Mockery::mock(ImageInterface::class); $this->assertNull($this->manipulator->getImage($image)); } public function testGetImageWithEmptyMarkParam() { - $image = Mockery::mock(ImageInterface::class); + $image = \Mockery::mock(ImageInterface::class); $this->assertNull($this->manipulator->setParams(['mark' => ''])->getImage($image)); } @@ -150,14 +149,14 @@ public function testGetImageWithoutWatermarksFilesystem() { $this->manipulator->setWatermarks(null); - $image = Mockery::mock(ImageInterface::class); + $image = \Mockery::mock(ImageInterface::class); $this->assertNull($this->manipulator->setParams(['mark' => 'image.jpg'])->getImage($image)); } public function testGetDimension() { - $image = Mockery::mock(ImageInterface::class); + $image = \Mockery::mock(ImageInterface::class); $image->shouldReceive('width')->andReturn(2000); $image->shouldReceive('height')->andReturn(1000); diff --git a/tests/Responses/PsrResponseFactoryTest.php b/tests/Responses/PsrResponseFactoryTest.php index 0bf65bcd..68b3fedb 100644 --- a/tests/Responses/PsrResponseFactoryTest.php +++ b/tests/Responses/PsrResponseFactoryTest.php @@ -2,14 +2,13 @@ namespace League\Glide\Responses; -use Mockery; use PHPUnit\Framework\TestCase; class PsrResponseFactoryTest extends TestCase { public function testCreateInstance() { - $response = Mockery::mock('Psr\Http\Message\ResponseInterface'); + $response = \Mockery::mock('Psr\Http\Message\ResponseInterface'); $streamCallback = function () { }; @@ -21,7 +20,7 @@ public function testCreateInstance() public function testCreate() { - $response = Mockery::mock('Psr\Http\Message\ResponseInterface', function ($mock) { + $response = \Mockery::mock('Psr\Http\Message\ResponseInterface', function ($mock) { $mock->shouldReceive('withBody')->andReturn($mock)->once(); $mock->shouldReceive('withHeader')->andReturn($mock)->times(4); }); @@ -30,11 +29,11 @@ public function testCreate() return $stream; }; - $cache = Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { + $cache = \Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { $mock->shouldReceive('mimeType')->andReturn('image/jpeg'); $mock->shouldReceive('fileSize')->andReturn(0); $mock->shouldReceive('readStream')->andReturn( - Mockery::mock('Psr\Http\Message\StreamInterface') + \Mockery::mock('Psr\Http\Message\StreamInterface') ); }); diff --git a/tests/ServerFactoryTest.php b/tests/ServerFactoryTest.php index 0ed1570a..74350c1d 100644 --- a/tests/ServerFactoryTest.php +++ b/tests/ServerFactoryTest.php @@ -2,8 +2,6 @@ namespace League\Glide; -use InvalidArgumentException; -use Mockery; use PHPUnit\Framework\TestCase; class ServerFactoryTest extends TestCase @@ -16,9 +14,9 @@ public function testCreateServerFactory() public function testGetServer() { $server = new ServerFactory([ - 'source' => Mockery::mock('League\Flysystem\FilesystemOperator'), - 'cache' => Mockery::mock('League\Flysystem\FilesystemOperator'), - 'response' => Mockery::mock('League\Glide\Responses\ResponseFactoryInterface'), + 'source' => \Mockery::mock('League\Flysystem\FilesystemOperator'), + 'cache' => \Mockery::mock('League\Flysystem\FilesystemOperator'), + 'response' => \Mockery::mock('League\Glide\Responses\ResponseFactoryInterface'), ]); $this->assertInstanceOf('League\Glide\Server', $server->getServer()); @@ -27,7 +25,7 @@ public function testGetServer() public function testGetSource() { $server = new ServerFactory([ - 'source' => Mockery::mock('League\Flysystem\FilesystemOperator'), + 'source' => \Mockery::mock('League\Flysystem\FilesystemOperator'), ]); $this->assertInstanceOf('League\Flysystem\FilesystemOperator', $server->getSource()); @@ -41,7 +39,7 @@ public function testGetSource() public function testGetSourceWithNoneSet() { - $this->expectException(InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('A "source" file system must be set.'); $server = new ServerFactory(); @@ -60,7 +58,7 @@ public function testGetSourcePathPrefix() public function testGetCache() { $server = new ServerFactory([ - 'cache' => Mockery::mock('League\Flysystem\FilesystemOperator'), + 'cache' => \Mockery::mock('League\Flysystem\FilesystemOperator'), ]); $this->assertInstanceOf('League\Flysystem\FilesystemOperator', $server->getCache()); @@ -74,7 +72,7 @@ public function testGetCache() public function testGetCacheWithNoneSet() { - $this->expectException(InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('A "cache" file system must be set.'); $server = new ServerFactory(); @@ -128,7 +126,7 @@ public function testGetCacheWithFileExtensions() public function testGetWatermarks() { $server = new ServerFactory([ - 'watermarks' => Mockery::mock('League\Flysystem\FilesystemOperator'), + 'watermarks' => \Mockery::mock('League\Flysystem\FilesystemOperator'), ]); $this->assertInstanceOf('League\Flysystem\FilesystemOperator', $server->getWatermarks()); @@ -242,7 +240,7 @@ public function testGetBaseUrl() public function testGetResponseFactory() { $server = new ServerFactory([ - 'response' => Mockery::mock('League\Glide\Responses\ResponseFactoryInterface'), + 'response' => \Mockery::mock('League\Glide\Responses\ResponseFactoryInterface'), ]); $this->assertInstanceOf('League\Glide\Responses\ResponseFactoryInterface', $server->getResponseFactory()); @@ -258,9 +256,9 @@ public function testGetResponseFactoryWithNoneSet() public function testCreate() { $server = ServerFactory::create([ - 'source' => Mockery::mock('League\Flysystem\FilesystemOperator'), - 'cache' => Mockery::mock('League\Flysystem\FilesystemOperator'), - 'response' => Mockery::mock('League\Glide\Responses\ResponseFactoryInterface'), + 'source' => \Mockery::mock('League\Flysystem\FilesystemOperator'), + 'cache' => \Mockery::mock('League\Flysystem\FilesystemOperator'), + 'response' => \Mockery::mock('League\Glide\Responses\ResponseFactoryInterface'), 'temp_dir' => __DIR__, ]); diff --git a/tests/ServerTest.php b/tests/ServerTest.php index bd58a63a..937077dc 100644 --- a/tests/ServerTest.php +++ b/tests/ServerTest.php @@ -3,10 +3,8 @@ namespace League\Glide; use Hamcrest\Matchers; -use InvalidArgumentException; use League\Glide\Filesystem\FileNotFoundException; use League\Glide\Filesystem\FilesystemException; -use Mockery; use PHPUnit\Framework\TestCase; class ServerTest extends TestCase @@ -15,9 +13,9 @@ class ServerTest extends TestCase public function setUp(): void { - $response = Mockery::mock('Psr\Http\Message\ResponseInterface'); + $response = \Mockery::mock('Psr\Http\Message\ResponseInterface'); - $responseFactory = Mockery::mock('League\Glide\Responses\ResponseFactoryInterface'); + $responseFactory = \Mockery::mock('League\Glide\Responses\ResponseFactoryInterface'); $responseFactory ->shouldReceive('create') ->andReturn($response) @@ -27,16 +25,16 @@ public function setUp(): void }); $this->server = new Server( - Mockery::mock('League\Flysystem\FilesystemOperator'), - Mockery::mock('League\Flysystem\FilesystemOperator'), - Mockery::mock('League\Glide\Api\ApiInterface'), + \Mockery::mock('League\Flysystem\FilesystemOperator'), + \Mockery::mock('League\Flysystem\FilesystemOperator'), + \Mockery::mock('League\Glide\Api\ApiInterface'), $responseFactory ); } public function tearDown(): void { - Mockery::close(); + \Mockery::close(); } public function testCreateInstance() @@ -46,7 +44,7 @@ public function testCreateInstance() public function testSetSource() { - $this->server->setSource(Mockery::mock('League\Flysystem\FilesystemOperator')); + $this->server->setSource(\Mockery::mock('League\Flysystem\FilesystemOperator')); $this->assertInstanceOf('League\Flysystem\FilesystemOperator', $this->server->getSource()); } @@ -102,7 +100,7 @@ public function testGetSourcePathWithEncodedEntities() public function testSourceFileExists() { - $this->server->setSource(Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { + $this->server->setSource(\Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { $mock->shouldReceive('fileExists')->with('image.jpg')->andReturn(true)->once(); })); @@ -122,7 +120,7 @@ public function testGetBaseUrl() public function testSetCache() { - $this->server->setCache(Mockery::mock('League\Flysystem\FilesystemOperator')); + $this->server->setCache(\Mockery::mock('League\Flysystem\FilesystemOperator')); $this->assertInstanceOf('League\Flysystem\FilesystemOperator', $this->server->getCache()); } @@ -315,7 +313,7 @@ public function testGetCachePathWithExtensionAndPjpgFmFromPreset() public function testCacheFileExists() { - $this->server->setCache(Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { + $this->server->setCache(\Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { $mock->shouldReceive('fileExists')->with('image.jpg/75094881e9fd2b93063d6a5cb083091c')->andReturn(true)->once(); })); @@ -324,7 +322,7 @@ public function testCacheFileExists() public function testDeleteCache() { - $this->server->setCache(Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { + $this->server->setCache(\Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { $mock->shouldReceive('deleteDirectory')->with('image.jpg')->andReturn(true)->once(); })); @@ -333,7 +331,7 @@ public function testDeleteCache() public function testDeleteCacheWithGroupCacheInFoldersDisabled() { - $this->expectException(InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Deleting cached image manipulations is not possible when grouping cache into folders is disabled.'); $this->server->setGroupCacheInFolders(false); @@ -343,7 +341,7 @@ public function testDeleteCacheWithGroupCacheInFoldersDisabled() public function testSetApi() { - $api = Mockery::mock('League\Glide\Api\ApiInterface'); + $api = \Mockery::mock('League\Glide\Api\ApiInterface'); $this->server->setApi($api); $this->assertInstanceOf('League\Glide\Api\ApiInterface', $this->server->getApi()); } @@ -419,7 +417,7 @@ public function testGetAllParams() public function testSetResponseFactory() { - $this->server->setResponseFactory(Mockery::mock('League\Glide\Responses\ResponseFactoryInterface')); + $this->server->setResponseFactory(\Mockery::mock('League\Glide\Responses\ResponseFactoryInterface')); $this->assertInstanceOf( 'League\Glide\Responses\ResponseFactoryInterface', @@ -434,11 +432,11 @@ public function testGetResponseFactory() public function testGetImageResponse() { - $this->server->setResponseFactory(Mockery::mock('League\Glide\Responses\ResponseFactoryInterface', function ($mock) { - $mock->shouldReceive('create')->andReturn(Mockery::mock('Psr\Http\Message\ResponseInterface')); + $this->server->setResponseFactory(\Mockery::mock('League\Glide\Responses\ResponseFactoryInterface', function ($mock) { + $mock->shouldReceive('create')->andReturn(\Mockery::mock('Psr\Http\Message\ResponseInterface')); })); - $this->server->setCache(Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { + $this->server->setCache(\Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { $mock->shouldReceive('fileExists')->andReturn(true); })); @@ -450,7 +448,7 @@ public function testGetImageResponse() public function testGetImageResponseWithoutResponseFactory() { - $this->expectException(InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Unable to get image response, no response factory defined.'); $this->server->getImageResponse('image.jpg', []); @@ -458,7 +456,7 @@ public function testGetImageResponseWithoutResponseFactory() public function testGetImageAsBase64() { - $this->server->setCache(Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { + $this->server->setCache(\Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { $mock->shouldReceive('fileExists')->andReturn(true); $mock->shouldReceive('mimeType')->andReturn('image/jpeg'); $mock->shouldReceive('read')->andReturn('content')->once(); @@ -475,7 +473,7 @@ public function testGetImageAsBase64WithUnreadableSource() $this->expectException(FilesystemException::class); $this->expectExceptionMessage('Could not read the image `image.jpg/75094881e9fd2b93063d6a5cb083091c`.'); - $this->server->setCache(Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { + $this->server->setCache(\Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { $mock->shouldReceive('fileExists')->andReturn(true); $mock->shouldReceive('mimeType')->andReturn('image/jpeg'); $mock->shouldReceive('read')->andThrow('League\Flysystem\UnableToReadFile')->once(); @@ -489,7 +487,7 @@ public function testGetImageAsBase64WithUnreadableSource() */ public function testOutputImage() { - $this->server->setCache(Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { + $this->server->setCache(\Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { $mock->shouldReceive('fileExists')->andReturn(true); $mock->shouldReceive('mimeType')->andReturn('image/jpeg'); $mock->shouldReceive('fileSize')->andReturn(0); @@ -509,17 +507,17 @@ public function testOutputImage() public function testMakeImageFromSource() { - $this->server->setSource(Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { + $this->server->setSource(\Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { $mock->shouldReceive('fileExists')->andReturn(true)->once(); $mock->shouldReceive('read')->andReturn('content')->once(); })); - $this->server->setCache(Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { + $this->server->setCache(\Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { $mock->shouldReceive('fileExists')->andReturn(false)->once(); $mock->shouldReceive('write')->with('image.jpg/75094881e9fd2b93063d6a5cb083091c', 'content')->once(); })); - $this->server->setApi(Mockery::mock('League\Glide\Api\ApiInterface', function ($mock) { + $this->server->setApi(\Mockery::mock('League\Glide\Api\ApiInterface', function ($mock) { $tmpDirPattern = Matchers::matchesPattern('~^'.sys_get_temp_dir().'.*~'); $mock->shouldReceive('run')->with($tmpDirPattern, [])->andReturn('content')->once(); })); @@ -532,18 +530,18 @@ public function testMakeImageFromSource() public function testMakeImageFromSourceWithCustomTmpDir() { - $this->server->setSource(Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { + $this->server->setSource(\Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { $mock->shouldReceive('fileExists')->andReturn(true)->once(); $mock->shouldReceive('read')->andReturn('content')->once(); })); - $this->server->setCache(Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { + $this->server->setCache(\Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { $mock->shouldReceive('fileExists')->andReturn(false)->once(); $mock->shouldReceive('write')->with('image.jpg/75094881e9fd2b93063d6a5cb083091c', 'content')->once(); })); $this->server->setTempDir(__DIR__); - $this->server->setApi(Mockery::mock('League\Glide\Api\ApiInterface', function ($mock) { + $this->server->setApi(\Mockery::mock('League\Glide\Api\ApiInterface', function ($mock) { $tmpDirPattern = Matchers::matchesPattern('~^'.__DIR__.'.*~'); $mock->shouldReceive('run')->with($tmpDirPattern, [])->andReturn('content')->once(); })); @@ -556,7 +554,7 @@ public function testMakeImageFromSourceWithCustomTmpDir() public function testMakeImageFromCache() { - $this->server->setCache(Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { + $this->server->setCache(\Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { $mock->shouldReceive('fileExists')->andReturn(true); })); @@ -571,11 +569,11 @@ public function testMakeImageFromSourceThatDoesNotExist() $this->expectException(FileNotFoundException::class); $this->expectExceptionMessage('Could not find the image `image.jpg`.'); - $this->server->setSource(Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { + $this->server->setSource(\Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { $mock->shouldReceive('fileExists')->andReturn(false)->once(); })); - $this->server->setCache(Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { + $this->server->setCache(\Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { $mock->shouldReceive('fileExists')->andReturn(false)->once(); })); @@ -587,12 +585,12 @@ public function testMakeImageWithUnreadableSource() $this->expectException(FilesystemException::class); $this->expectExceptionMessage('Could not read the image `image.jpg`.'); - $this->server->setSource(Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { + $this->server->setSource(\Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { $mock->shouldReceive('fileExists')->andReturn(true)->once(); $mock->shouldReceive('read')->andThrow('League\Flysystem\UnableToReadFile')->once(); })); - $this->server->setCache(Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { + $this->server->setCache(\Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { $mock->shouldReceive('fileExists')->andThrow('League\Flysystem\UnableToCheckFileExistence')->once(); })); @@ -604,17 +602,17 @@ public function testMakeImageWithUnwritableCache() $this->expectException(FilesystemException::class); $this->expectExceptionMessage('Could not write the image `image.jpg/75094881e9fd2b93063d6a5cb083091c`.'); - $this->server->setSource(Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { + $this->server->setSource(\Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { $mock->shouldReceive('fileExists')->andReturn(true)->once(); $mock->shouldReceive('read')->andReturn('content')->once(); })); - $this->server->setCache(Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { + $this->server->setCache(\Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { $mock->shouldReceive('fileExists')->andThrow('League\Flysystem\UnableToCheckFileExistence')->once(); $mock->shouldReceive('write')->andThrow('League\Flysystem\UnableToWriteFile')->once(); })); - $this->server->setApi(Mockery::mock('League\Glide\Api\ApiInterface', function ($mock) { + $this->server->setApi(\Mockery::mock('League\Glide\Api\ApiInterface', function ($mock) { $mock->shouldReceive('run')->andReturn('content')->once(); })); From 0ed379c318915984ad2c8136fb4a87a7eda93f81 Mon Sep 17 00:00:00 2001 From: Konnng Date: Wed, 24 Jan 2024 11:31:45 -0300 Subject: [PATCH 33/64] fix Encode manipulator --- src/Manipulators/Encode.php | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/Manipulators/Encode.php b/src/Manipulators/Encode.php index 3439859a..44871209 100644 --- a/src/Manipulators/Encode.php +++ b/src/Manipulators/Encode.php @@ -2,7 +2,12 @@ namespace League\Glide\Manipulators; +use Intervention\Image\Encoders\AutoEncoder; +use Intervention\Image\ImageManager; use Intervention\Image\Interfaces\ImageInterface; +use Intervention\Image\Drivers\Imagick\Driver as ImagickDriver; +use Intervention\Image\Drivers\Gd\Driver as GdDriver; + /** * @property string $fm @@ -21,19 +26,31 @@ public function run(ImageInterface $image): ImageInterface { $format = $this->getFormat($image); $quality = $this->getQuality(); + $driver = $image->driver(); if (in_array($format, ['jpg', 'pjpg'], true)) { - $image = $image->getDriver() - ->newImage($image->width(), $image->height(), '#fff') - ->insert($image, 'top-left', 0, 0); + $image = (new ImageManager($driver)) + ->create($image->width(), $image->height()) + ->fill('ffffff') + ->place($image, 'top-left', 0, 0); } - if ('pjpg' === $format) { - $image->interlace(); - $format = 'jpg'; + if (in_array($format, ['png', 'pjpg'], true)) { + $i = $image->core()->native(); + if ($driver instanceof ImagickDriver) { + $i->setInterlaceScheme(3); // 3 = Imagick::INTERLACE_PLANE constant + } else if ($driver instanceof GdDriver) { + imageinterlace($i, true); + } + + if ($format === 'pjpg') { + $format = 'jpg'; + } } - return $image->encode($format, $quality); + return (new ImageManager($driver))->read( + $image->encodeByExtension($format, $quality)->toDataUri() + ); } /** @@ -49,7 +66,7 @@ public function getFormat(ImageInterface $image) return $this->fm; } - return array_search($image->mime(), static::supportedFormats(), true) ?: 'jpg'; + return array_search($image->encode(new AutoEncoder())->mediaType(), static::supportedFormats(), true) ?: 'jpg'; } /** From a786e51121f85a18144961dcdcba45eb37284106 Mon Sep 17 00:00:00 2001 From: Art4 Date: Wed, 24 Jan 2024 16:29:07 +0100 Subject: [PATCH 34/64] Move Encoding into Api::run(), remove orientate(), interlace(), Encode manipulator --- src/Api/Api.php | 38 +++++++++++++++++++++++++++++--- src/Manipulators/Encode.php | 17 +++++++++----- src/Manipulators/Orientation.php | 3 ++- src/ServerFactory.php | 3 ++- 4 files changed, 51 insertions(+), 10 deletions(-) diff --git a/src/Api/Api.php b/src/Api/Api.php index 09aff921..c46a83bb 100644 --- a/src/Api/Api.php +++ b/src/Api/Api.php @@ -3,6 +3,7 @@ namespace League\Glide\Api; use Intervention\Image\ImageManager; +use League\Glide\Manipulators\Encode; use League\Glide\Manipulators\ManipulatorInterface; class Api implements ApiInterface @@ -17,7 +18,7 @@ class Api implements ApiInterface /** * Collection of manipulators. * - * @var array + * @var ManipulatorInterface[] */ protected $manipulators; @@ -58,7 +59,7 @@ public function getImageManager() /** * Set the manipulators. * - * @param array $manipulators Collection of manipulators. + * @param ManipulatorInterface[] $manipulators Collection of manipulators. * * @return void */ @@ -101,6 +102,37 @@ public function run($source, array $params) $image = $manipulator->run($image); } - return $image->getEncoded(); + $encode = new Encode(); + $encode->setParams($params); + + switch ($encode->fm) { + case 'avif': + $encodedImage = $image->toAvif($encode->getQuality()); + break; + + case 'gif': + $encodedImage = $image->toGif($encode->getQuality()); + break; + + case 'png': + $encodedImage = $image->toPng($encode->getQuality()); + break; + + case 'webp': + $encodedImage = $image->toWebp($encode->getQuality()); + break; + + case 'tiff': + $encodedImage = $image->toTiff($encode->getQuality()); + break; + + case 'jpg': + case 'pjpg': + default: + $encodedImage = $image->toJpeg($encode->getQuality()); + break; + } + + return $encodedImage->toString(); } } diff --git a/src/Manipulators/Encode.php b/src/Manipulators/Encode.php index 3439859a..12a3280e 100644 --- a/src/Manipulators/Encode.php +++ b/src/Manipulators/Encode.php @@ -19,17 +19,22 @@ class Encode extends BaseManipulator */ public function run(ImageInterface $image): ImageInterface { + // TODO: Encoding was moved to Api::run() + return $image; + $format = $this->getFormat($image); $quality = $this->getQuality(); if (in_array($format, ['jpg', 'pjpg'], true)) { - $image = $image->getDriver() - ->newImage($image->width(), $image->height(), '#fff') - ->insert($image, 'top-left', 0, 0); + $image = $image->driver() + ->createImage($image->width(), $image->height()) + ->fill('#fff') + ->place($image, 'top-left', 0, 0); } if ('pjpg' === $format) { - $image->interlace(); + // TODO: interlace() was removed + // $image->interlace(); $format = 'jpg'; } @@ -49,7 +54,9 @@ public function getFormat(ImageInterface $image) return $this->fm; } - return array_search($image->mime(), static::supportedFormats(), true) ?: 'jpg'; + // TODO: Image::mime() was removed + // return array_search($image->mime(), static::supportedFormats(), true) ?: 'jpg'; + return 'jpg'; } /** diff --git a/src/Manipulators/Orientation.php b/src/Manipulators/Orientation.php index 30dcfa42..697ecd2d 100644 --- a/src/Manipulators/Orientation.php +++ b/src/Manipulators/Orientation.php @@ -21,7 +21,8 @@ public function run(ImageInterface $image): ImageInterface $orientation = $this->getOrientation(); if ('auto' === $orientation) { - return $image->orientate(); + // TODO: orientate() has been removed + // return $image->orientate(); } return $image->rotate((float) $orientation); diff --git a/src/ServerFactory.php b/src/ServerFactory.php index 2ee849e0..dce1904e 100644 --- a/src/ServerFactory.php +++ b/src/ServerFactory.php @@ -278,7 +278,8 @@ public function getManipulators() new Watermark($this->getWatermarks(), $this->getWatermarksPathPrefix() ?: ''), new Background(), new Border(), - new Encode(), + // TODO: Encoding was moved to Api::run() + // new Encode(), ]; } From e3b3dc1e8ab5c864250f905deea48676f95317cc Mon Sep 17 00:00:00 2001 From: Konnng Date: Wed, 24 Jan 2024 14:38:02 -0300 Subject: [PATCH 35/64] fix Encoder modifier to detect file format properly --- src/Manipulators/Encode.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Manipulators/Encode.php b/src/Manipulators/Encode.php index 44871209..548beae1 100644 --- a/src/Manipulators/Encode.php +++ b/src/Manipulators/Encode.php @@ -2,7 +2,6 @@ namespace League\Glide\Manipulators; -use Intervention\Image\Encoders\AutoEncoder; use Intervention\Image\ImageManager; use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Drivers\Imagick\Driver as ImagickDriver; @@ -49,7 +48,7 @@ public function run(ImageInterface $image): ImageInterface } return (new ImageManager($driver))->read( - $image->encodeByExtension($format, $quality)->toDataUri() + $image->encodeByExtension($format, $quality)->toFilePointer() ); } @@ -66,7 +65,7 @@ public function getFormat(ImageInterface $image) return $this->fm; } - return array_search($image->encode(new AutoEncoder())->mediaType(), static::supportedFormats(), true) ?: 'jpg'; + return array_search($image->origin()->mediaType(), static::supportedFormats(), true) ?: 'jpg'; } /** From 510ec6454e79b6184354c8bffdfde1132df96075 Mon Sep 17 00:00:00 2001 From: Konnng Date: Wed, 24 Jan 2024 14:38:15 -0300 Subject: [PATCH 36/64] fix Encoder Modifier tests --- tests/Manipulators/EncodeTest.php | 116 +++++++++++++++++------------- 1 file changed, 66 insertions(+), 50 deletions(-) diff --git a/tests/Manipulators/EncodeTest.php b/tests/Manipulators/EncodeTest.php index d0b2d165..8b7080ed 100644 --- a/tests/Manipulators/EncodeTest.php +++ b/tests/Manipulators/EncodeTest.php @@ -20,16 +20,26 @@ class EncodeTest extends TestCase public function setUp(): void { $manager = ImageManager::gd(); - $this->jpg = $manager->create(100, 100)->encode(new MediaTypeEncoder('image/jpeg')); - $this->png = $manager->create(100, 100)->encode(new MediaTypeEncoder('image/png')); - $this->gif = $manager->create(100, 100)->encode(new MediaTypeEncoder('image/gif')); + $this->jpg = $manager->read( + $manager->create(100, 100)->encode(new MediaTypeEncoder('image/jpeg'))->toFilePointer() + ); + $this->png = $manager->read( + $manager->create(100, 100)->encode(new MediaTypeEncoder('image/png'))->toFilePointer() + ); + $this->gif = $manager->read( + $manager->create(100, 100)->encode(new MediaTypeEncoder('image/gif'))->toFilePointer() + ); if (function_exists('imagecreatefromwebp')) { - $this->webp = $manager->create(100, 100)->encode(new MediaTypeEncoder('webp')); + $this->webp = $manager->read( + $manager->create(100, 100)->encode(new MediaTypeEncoder('image/webp'))->toFilePointer() + ); } if (function_exists('imagecreatefromavif')) { - $this->avif = $manager->create(100, 100)->encode(new MediaTypeEncoder('avif')); + $this->avif = $manager->read( + $manager->create(100, 100)->encode(new MediaTypeEncoder('image/avif'))->toFilePointer() + ); } $this->manipulator = new Encode(); @@ -47,60 +57,61 @@ public function testCreateInstance() public function testRun() { - $this->assertSame('image/jpeg', $this->manipulator->setParams(['fm' => 'jpg'])->run($this->jpg)->mime); - $this->assertSame('image/jpeg', $this->manipulator->setParams(['fm' => 'jpg'])->run($this->png)->mime); - $this->assertSame('image/jpeg', $this->manipulator->setParams(['fm' => 'jpg'])->run($this->gif)->mime); - $this->assertSame('image/jpeg', $this->manipulator->setParams(['fm' => 'pjpg'])->run($this->jpg)->mime); - $this->assertSame('image/jpeg', $this->manipulator->setParams(['fm' => 'pjpg'])->run($this->png)->mime); - $this->assertSame('image/jpeg', $this->manipulator->setParams(['fm' => 'pjpg'])->run($this->gif)->mime); - $this->assertSame('image/png', $this->manipulator->setParams(['fm' => 'png'])->run($this->jpg)->mime); - $this->assertSame('image/png', $this->manipulator->setParams(['fm' => 'png'])->run($this->png)->mime); - $this->assertSame('image/png', $this->manipulator->setParams(['fm' => 'png'])->run($this->gif)->mime); - $this->assertSame('image/gif', $this->manipulator->setParams(['fm' => 'gif'])->run($this->jpg)->mime); - $this->assertSame('image/gif', $this->manipulator->setParams(['fm' => 'gif'])->run($this->png)->mime); - $this->assertSame('image/gif', $this->manipulator->setParams(['fm' => 'gif'])->run($this->gif)->mime); + $this->assertSame('image/jpeg', $this->getMime($this->manipulator->setParams(['fm' => 'jpg'])->run($this->jpg))); + $this->assertSame('image/jpeg', $this->getMime($this->manipulator->setParams(['fm' => 'jpg'])->run($this->png))); + $this->assertSame('image/jpeg', $this->getMime($this->manipulator->setParams(['fm' => 'jpg'])->run($this->gif))); + $this->assertSame('image/jpeg', $this->getMime($this->manipulator->setParams(['fm' => 'pjpg'])->run($this->jpg))); + $this->assertSame('image/jpeg', $this->getMime($this->manipulator->setParams(['fm' => 'pjpg'])->run($this->png))); + $this->assertSame('image/jpeg', $this->getMime($this->manipulator->setParams(['fm' => 'pjpg'])->run($this->gif))); + $this->assertSame('image/png', $this->getMime($this->manipulator->setParams(['fm' => 'png'])->run($this->jpg))); + $this->assertSame('image/png', $this->getMime($this->manipulator->setParams(['fm' => 'png'])->run($this->png))); + $this->assertSame('image/png', $this->getMime($this->manipulator->setParams(['fm' => 'png'])->run($this->gif))); + $this->assertSame('image/gif', $this->getMime($this->manipulator->setParams(['fm' => 'gif'])->run($this->jpg))); + $this->assertSame('image/gif', $this->getMime($this->manipulator->setParams(['fm' => 'gif'])->run($this->png))); + $this->assertSame('image/gif', $this->getMime($this->manipulator->setParams(['fm' => 'gif'])->run($this->gif))); if (function_exists('imagecreatefromwebp')) { - $this->assertSame('image/jpeg', $this->manipulator->setParams(['fm' => 'jpg'])->run($this->webp)->mime); - $this->assertSame('image/jpeg', $this->manipulator->setParams(['fm' => 'pjpg'])->run($this->webp)->mime); - $this->assertSame('image/png', $this->manipulator->setParams(['fm' => 'png'])->run($this->webp)->mime); - $this->assertSame('image/gif', $this->manipulator->setParams(['fm' => 'gif'])->run($this->webp)->mime); - $this->assertSame('image/webp', $this->manipulator->setParams(['fm' => 'webp'])->run($this->jpg)->mime); - $this->assertSame('image/webp', $this->manipulator->setParams(['fm' => 'webp'])->run($this->png)->mime); - $this->assertSame('image/webp', $this->manipulator->setParams(['fm' => 'webp'])->run($this->gif)->mime); - $this->assertSame('image/webp', $this->manipulator->setParams(['fm' => 'webp'])->run($this->webp)->mime); + $this->assertSame('image/jpeg', $this->getMime($this->manipulator->setParams(['fm' => 'jpg'])->run($this->webp))); + $this->assertSame('image/jpeg', $this->getMime($this->manipulator->setParams(['fm' => 'pjpg'])->run($this->webp))); + $this->assertSame('image/png', $this->getMime($this->manipulator->setParams(['fm' => 'png'])->run($this->webp))); + $this->assertSame('image/gif', $this->getMime($this->manipulator->setParams(['fm' => 'gif'])->run($this->webp))); + $this->assertSame('image/webp', $this->getMime($this->manipulator->setParams(['fm' => 'webp'])->run($this->jpg))); + $this->assertSame('image/webp', $this->getMime($this->manipulator->setParams(['fm' => 'webp'])->run($this->png))); + $this->assertSame('image/webp', $this->getMime($this->manipulator->setParams(['fm' => 'webp'])->run($this->gif))); + $this->assertSame('image/webp', $this->getMime($this->manipulator->setParams(['fm' => 'webp'])->run($this->webp))); } if (function_exists('imagecreatefromavif')) { - $this->assertSame('image/jpeg', $this->manipulator->setParams(['fm' => 'jpg'])->run($this->avif)->mime); - $this->assertSame('image/jpeg', $this->manipulator->setParams(['fm' => 'pjpg'])->run($this->avif)->mime); - $this->assertSame('image/png', $this->manipulator->setParams(['fm' => 'png'])->run($this->avif)->mime); - $this->assertSame('image/gif', $this->manipulator->setParams(['fm' => 'gif'])->run($this->avif)->mime); - $this->assertSame('image/avif', $this->manipulator->setParams(['fm' => 'avif'])->run($this->jpg)->mime); - $this->assertSame('image/avif', $this->manipulator->setParams(['fm' => 'avif'])->run($this->png)->mime); - $this->assertSame('image/avif', $this->manipulator->setParams(['fm' => 'avif'])->run($this->gif)->mime); - $this->assertSame('image/avif', $this->manipulator->setParams(['fm' => 'avif'])->run($this->avif)->mime); + $this->assertSame('image/jpeg', $this->getMime($this->manipulator->setParams(['fm' => 'jpg'])->run($this->avif))); + $this->assertSame('image/jpeg', $this->getMime($this->manipulator->setParams(['fm' => 'pjpg'])->run($this->avif))); + $this->assertSame('image/png', $this->getMime($this->manipulator->setParams(['fm' => 'png'])->run($this->avif))); + $this->assertSame('image/gif', $this->getMime($this->manipulator->setParams(['fm' => 'gif'])->run($this->avif))); + $this->assertSame('image/avif', $this->getMime($this->manipulator->setParams(['fm' => 'avif'])->run($this->jpg))); + $this->assertSame('image/avif', $this->getMime($this->manipulator->setParams(['fm' => 'avif'])->run($this->png))); + $this->assertSame('image/avif', $this->getMime($this->manipulator->setParams(['fm' => 'avif'])->run($this->gif))); + $this->assertSame('image/avif', $this->getMime($this->manipulator->setParams(['fm' => 'avif'])->run($this->avif))); } if (function_exists('imagecreatefromwebp') && function_exists('imagecreatefromavif')) { - $this->assertSame('image/webp', $this->manipulator->setParams(['fm' => 'webp'])->run($this->avif)->mime); - $this->assertSame('image/avif', $this->manipulator->setParams(['fm' => 'avif'])->run($this->webp)->mime); + $this->assertSame('image/webp', $this->getMime($this->manipulator->setParams(['fm' => 'webp'])->run($this->avif))); + $this->assertSame('image/avif', $this->getMime($this->manipulator->setParams(['fm' => 'avif'])->run($this->webp))); } } public function testGetFormat() { $image = \Mockery::mock(ImageInterface::class, function ($mock) { - $mock->shouldReceive('mime')->andReturn('image/jpeg')->once(); - $mock->shouldReceive('mime')->andReturn('image/png')->once(); - $mock->shouldReceive('mime')->andReturn('image/gif')->once(); - $mock->shouldReceive('mime')->andReturn('image/bmp')->once(); - $mock->shouldReceive('mime')->andReturn('image/jpeg')->twice(); + $mock->shouldReceive('origin')->andReturn(\Mockery::mock('Intervention\Image\Origin', ['mediaType' => 'image/jpeg']))->once(); + $mock->shouldReceive('origin')->andReturn(\Mockery::mock('Intervention\Image\Origin', ['mediaType' => 'image/png']))->once(); + $mock->shouldReceive('origin')->andReturn(\Mockery::mock('Intervention\Image\Origin', ['mediaType' => 'image/gif']))->once(); + $mock->shouldReceive('origin')->andReturn(\Mockery::mock('Intervention\Image\Origin', ['mediaType' => 'image/bmp']))->once(); + $mock->shouldReceive('origin')->andReturn(\Mockery::mock('Intervention\Image\Origin', ['mediaType' => 'image/jpeg']))->twice(); if (function_exists('imagecreatefromwebp')) { - $mock->shouldReceive('mime')->andReturn('image/webp')->once(); + $mock->shouldReceive('origin')->andReturn(\Mockery::mock('Intervention\Image\Origin', ['mediaType' => 'image/webp']))->once(); } + if (function_exists('imagecreatefromavif')) { - $mock->shouldReceive('mime')->andReturn('image/avif')->once(); + $mock->shouldReceive('origin')->andReturn(\Mockery::mock('Intervention\Image\Origin', ['mediaType' => 'image/avif']))->once(); } }); @@ -148,13 +159,18 @@ public function testWithImagick() } $manager = ImageManager::imagick(); // These need to be recreated with the imagick driver selected in the manager - $this->jpg = $manager->create(100, 100)->encode(new MediaTypeEncoder('image/jpeg')); - $this->png = $manager->create(100, 100)->encode(new MediaTypeEncoder('image/png')); - $this->gif = $manager->create(100, 100)->encode(new MediaTypeEncoder('image/gif')); - $this->tif = $manager->create(100, 100)->encode(new MediaTypeEncoder('image/tiff')); - - $this->assertSame('image/tiff', $this->manipulator->setParams(['fm' => 'tiff'])->run($this->jpg)->mime); - $this->assertSame('image/tiff', $this->manipulator->setParams(['fm' => 'tiff'])->run($this->png)->mime); - $this->assertSame('image/tiff', $this->manipulator->setParams(['fm' => 'tiff'])->run($this->gif)->mime); + $this->jpg = $manager->read($manager->create(100, 100)->encode(new MediaTypeEncoder('image/jpeg'))->toFilePointer()); + $this->png = $manager->read($manager->create(100, 100)->encode(new MediaTypeEncoder('image/png'))->toFilePointer()); + $this->gif = $manager->read($manager->create(100, 100)->encode(new MediaTypeEncoder('image/gif'))->toFilePointer()); + $this->tif = $manager->read($manager->create(100, 100)->encode(new MediaTypeEncoder('image/tiff'))->toFilePointer()); + + $this->assertSame('image/tiff', $this->getMime($this->manipulator->setParams(['fm' => 'tiff'])->run($this->jpg))); + $this->assertSame('image/tiff', $this->getMime($this->manipulator->setParams(['fm' => 'tiff'])->run($this->png))); + $this->assertSame('image/tiff', $this->getMime($this->manipulator->setParams(['fm' => 'tiff'])->run($this->gif))); + } + + public function getMime(ImageInterface $image) + { + return $image->origin()->mediaType(); } } From 907b1bcc4c28b2758ec44e78f9ba95536798e115 Mon Sep 17 00:00:00 2001 From: Konnng Date: Wed, 24 Jan 2024 15:03:09 -0300 Subject: [PATCH 37/64] improve Orientation Modifier --- src/Manipulators/Orientation.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Manipulators/Orientation.php b/src/Manipulators/Orientation.php index 5dbd2555..36e4b06e 100644 --- a/src/Manipulators/Orientation.php +++ b/src/Manipulators/Orientation.php @@ -19,9 +19,10 @@ class Orientation extends BaseManipulator public function run(ImageInterface $image): ImageInterface { $orientation = $this->getOrientation(); + $originalOrientation = $image->exif('Orientation'); - if ('auto' === $orientation && $image->exif('Orientation')) { - switch ($image->exif('Orientation')) { + if ('auto' === $orientation && is_numeric($originalOrientation)) { + switch ($originalOrientation) { case 2: $image->flip(); break; From 7fe32eefe580f3de267d2790727a319327138576 Mon Sep 17 00:00:00 2001 From: Konnng Date: Wed, 24 Jan 2024 15:03:23 -0300 Subject: [PATCH 38/64] fix Orientation Modifier tests --- tests/Manipulators/OrientationTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/Manipulators/OrientationTest.php b/tests/Manipulators/OrientationTest.php index 18dc7039..bcc01a5b 100644 --- a/tests/Manipulators/OrientationTest.php +++ b/tests/Manipulators/OrientationTest.php @@ -27,7 +27,9 @@ public function testCreateInstance() public function testRun() { $image = \Mockery::mock(ImageInterface::class, function ($mock) { - $mock->shouldReceive('orientate')->andReturn($mock)->once(); + $mock->shouldReceive('exif')->withArgs(['Orientation'])->andReturn(null)->twice(); + + $mock->shouldReceive('rotate')->andReturn($mock)->with('0')->once(); $mock->shouldReceive('rotate')->andReturn($mock)->with('90')->once(); }); From 14bdf5d2cb0388b6ffc3b2bc9a02927fbec939bf Mon Sep 17 00:00:00 2001 From: Konnng Date: Wed, 24 Jan 2024 15:34:30 -0300 Subject: [PATCH 39/64] fixed code formatting --- src/Manipulators/Encode.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Manipulators/Encode.php b/src/Manipulators/Encode.php index 548beae1..b730e074 100644 --- a/src/Manipulators/Encode.php +++ b/src/Manipulators/Encode.php @@ -2,11 +2,10 @@ namespace League\Glide\Manipulators; +use Intervention\Image\Drivers\Gd\Driver as GdDriver; +use Intervention\Image\Drivers\Imagick\Driver as ImagickDriver; use Intervention\Image\ImageManager; use Intervention\Image\Interfaces\ImageInterface; -use Intervention\Image\Drivers\Imagick\Driver as ImagickDriver; -use Intervention\Image\Drivers\Gd\Driver as GdDriver; - /** * @property string $fm @@ -38,11 +37,11 @@ public function run(ImageInterface $image): ImageInterface $i = $image->core()->native(); if ($driver instanceof ImagickDriver) { $i->setInterlaceScheme(3); // 3 = Imagick::INTERLACE_PLANE constant - } else if ($driver instanceof GdDriver) { + } elseif ($driver instanceof GdDriver) { imageinterlace($i, true); } - if ($format === 'pjpg') { + if ('pjpg' === $format) { $format = 'jpg'; } } From 3d015917974e684f9e6f842f3f7562a6c73a5976 Mon Sep 17 00:00:00 2001 From: Konnng Date: Wed, 24 Jan 2024 15:34:38 -0300 Subject: [PATCH 40/64] fix Server Tests --- tests/ServerTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/ServerTest.php b/tests/ServerTest.php index 937077dc..53c6fe87 100644 --- a/tests/ServerTest.php +++ b/tests/ServerTest.php @@ -514,12 +514,12 @@ public function testMakeImageFromSource() $this->server->setCache(\Mockery::mock('League\Flysystem\FilesystemOperator', function ($mock) { $mock->shouldReceive('fileExists')->andReturn(false)->once(); - $mock->shouldReceive('write')->with('image.jpg/75094881e9fd2b93063d6a5cb083091c', 'content')->once(); + $mock->shouldReceive('write')->withArgs(['image.jpg/75094881e9fd2b93063d6a5cb083091c', 'content'])->once(); })); $this->server->setApi(\Mockery::mock('League\Glide\Api\ApiInterface', function ($mock) { - $tmpDirPattern = Matchers::matchesPattern('~^'.sys_get_temp_dir().'.*~'); - $mock->shouldReceive('run')->with($tmpDirPattern, [])->andReturn('content')->once(); + $tmpDirPattern = Matchers::matchesPattern('~\/?'.sys_get_temp_dir().'.*~'); + $mock->shouldReceive('run')->withArgs([$tmpDirPattern, []])->andReturn('content')->once(); })); $this->assertEquals( From 9bc8881081c8af193d46d5c0191b0c1b9041a653 Mon Sep 17 00:00:00 2001 From: Konnng Date: Wed, 24 Jan 2024 15:34:45 -0300 Subject: [PATCH 41/64] .gitignore updated --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 74c4b859..fefeecec 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ docs/_site .php-cs-fixer.cache .phpunit.result.cache composer.lock +.history From 2957c80112903002410f18fe1a34b5e0df255991 Mon Sep 17 00:00:00 2001 From: Konnng Date: Wed, 24 Jan 2024 16:21:39 -0300 Subject: [PATCH 42/64] Fix Background Modifier --- src/Manipulators/Background.php | 4 ++-- tests/Manipulators/BackgroundTest.php | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Manipulators/Background.php b/src/Manipulators/Background.php index fdfeb6d2..2166541d 100644 --- a/src/Manipulators/Background.php +++ b/src/Manipulators/Background.php @@ -27,8 +27,8 @@ public function run(ImageInterface $image): ImageInterface if ($color) { $new = $image->driver()->createImage($image->width(), $image->height())->fill($color); - // TODO: Find a way to communicate the mime - // $new->mime = $image->mime; + $new->mime = $image->origin()->mediaType(); + $image = $new->place($image, 'top-left', 0, 0); } diff --git a/tests/Manipulators/BackgroundTest.php b/tests/Manipulators/BackgroundTest.php index d049a114..ba55096b 100644 --- a/tests/Manipulators/BackgroundTest.php +++ b/tests/Manipulators/BackgroundTest.php @@ -25,6 +25,8 @@ public function testRun() $image = \Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('width')->andReturn(100)->once(); $mock->shouldReceive('height')->andReturn(100)->once(); + $mock->shouldReceive('origin')->andReturn(\Mockery::mock('Intervention\Image\Origin', ['mediaType' => 'image/jpeg']))->once(); + $mock->shouldReceive('driver')->andReturn(\Mockery::mock(DriverInterface::class, function ($mock) { $mock->shouldReceive('createImage')->with(100, 100)->andReturn(\Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('fill')->with('rgba(0, 0, 0, 1)')->andReturn(\Mockery::mock(ImageInterface::class, function ($mock) { From f51a6278e881db70ec5c1b8a18b0e1283a8f2bba Mon Sep 17 00:00:00 2001 From: Konnng Date: Wed, 24 Jan 2024 17:27:58 -0300 Subject: [PATCH 43/64] fix Background Modifier --- src/Manipulators/Background.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Manipulators/Background.php b/src/Manipulators/Background.php index 2166541d..ed1b7b6a 100644 --- a/src/Manipulators/Background.php +++ b/src/Manipulators/Background.php @@ -2,7 +2,9 @@ namespace League\Glide\Manipulators; +use Intervention\Image\ImageManager; use Intervention\Image\Interfaces\ImageInterface; +use Intervention\Image\Origin; use League\Glide\Manipulators\Helpers\Color; /** @@ -26,10 +28,14 @@ public function run(ImageInterface $image): ImageInterface $color = (new Color($this->bg))->formatted(); if ($color) { - $new = $image->driver()->createImage($image->width(), $image->height())->fill($color); - $new->mime = $image->origin()->mediaType(); + $new = $image->driver()->createImage($image->width(), $image->height()) + ->fill($color) + ->place($image, 'top-left', 0, 0) + ->setOrigin( + new Origin($image->origin()->mediaType()) + ); - $image = $new->place($image, 'top-left', 0, 0); + $image = $new; } return $image; From 6a96ab747333a5fdee713217ef93d2916688e1b7 Mon Sep 17 00:00:00 2001 From: Konnng Date: Wed, 24 Jan 2024 17:28:05 -0300 Subject: [PATCH 44/64] fix Background Modifier Test --- tests/Manipulators/BackgroundTest.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tests/Manipulators/BackgroundTest.php b/tests/Manipulators/BackgroundTest.php index ba55096b..8f51844b 100644 --- a/tests/Manipulators/BackgroundTest.php +++ b/tests/Manipulators/BackgroundTest.php @@ -4,6 +4,7 @@ use Intervention\Image\Interfaces\DriverInterface; use Intervention\Image\Interfaces\ImageInterface; +use Intervention\Image\Origin; use PHPUnit\Framework\TestCase; class BackgroundTest extends TestCase @@ -23,13 +24,18 @@ public function testCreateInstance() public function testRun() { $image = \Mockery::mock(ImageInterface::class, function ($mock) { + $originMock = \Mockery::mock(Origin::class, ['mediaType' => 'image/jpeg']); + $mock->shouldReceive('width')->andReturn(100)->once(); $mock->shouldReceive('height')->andReturn(100)->once(); - $mock->shouldReceive('origin')->andReturn(\Mockery::mock('Intervention\Image\Origin', ['mediaType' => 'image/jpeg']))->once(); - - $mock->shouldReceive('driver')->andReturn(\Mockery::mock(DriverInterface::class, function ($mock) { - $mock->shouldReceive('createImage')->with(100, 100)->andReturn(\Mockery::mock(ImageInterface::class, function ($mock) { - $mock->shouldReceive('fill')->with('rgba(0, 0, 0, 1)')->andReturn(\Mockery::mock(ImageInterface::class, function ($mock) { + $mock->shouldReceive('origin')->andReturn($originMock)->once(); + + $mock->shouldReceive('driver')->andReturn(\Mockery::mock(DriverInterface::class, function ($mock) use ($originMock) { + $mock->shouldReceive('createImage')->with(100, 100)->andReturn(\Mockery::mock(ImageInterface::class, function ($mock) use ($originMock) { + $mock->shouldReceive('fill')->with('rgba(0, 0, 0, 1)')->andReturn(\Mockery::mock(ImageInterface::class, function ($mock) use ($originMock) { + $mock->shouldReceive('setOrigin')->withArgs(function ($arg1) { + return $arg1 instanceof Origin; + })->andReturn($mock)->once(); $mock->shouldReceive('place')->andReturn($mock)->once(); }))->once(); }))->once(); From 35170bddfb59283c65698f482f948af00f432cca Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 25 Jan 2024 10:22:37 +0100 Subject: [PATCH 45/64] Fix border manipulator --- src/Manipulators/Border.php | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/Manipulators/Border.php b/src/Manipulators/Border.php index 697014af..030ef0d5 100644 --- a/src/Manipulators/Border.php +++ b/src/Manipulators/Border.php @@ -2,6 +2,7 @@ namespace League\Glide\Manipulators; +use Intervention\Image\Geometry\Factories\RectangleFactory; use Intervention\Image\Interfaces\ImageInterface; use League\Glide\Manipulators\Helpers\Color; use League\Glide\Manipulators\Helpers\Dimension; @@ -139,13 +140,15 @@ public function getDpr() */ public function runOverlay(ImageInterface $image, $width, $color): ImageInterface { - return $image->rectangle( + return $image->drawRectangle( (int) round($width / 2), (int) round($width / 2), - (int) round($image->width() - ($width / 2)), - (int) round($image->height() - ($width / 2)), - function ($draw) use ($width, $color) { - $draw->border($width, $color); + function (RectangleFactory $rectangle) use ($image, $width, $color) { + $rectangle->size( + (int) round($image->width() - $width), + (int) round($image->height() - $width), + ); + $rectangle->border($color, $width); } ); } @@ -166,12 +169,11 @@ public function runShrink(ImageInterface $image, $width, $color): ImageInterface (int) round($image->width() - ($width * 2)), (int) round($image->height() - ($width * 2)) ) - ->resizeCanvas( + ->resizeCanvasRelative( (int) round($width * 2), (int) round($width * 2), + $color, 'center', - true, - $color ); } @@ -186,12 +188,11 @@ public function runShrink(ImageInterface $image, $width, $color): ImageInterface */ public function runExpand(ImageInterface $image, $width, $color): ImageInterface { - return $image->resizeCanvas( + return $image->resizeCanvasRelative( (int) round($width * 2), (int) round($width * 2), + $color, 'center', - true, - $color ); } } From f5f3476b15942685fc9ce3c984b6f56ade7da0de Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 25 Jan 2024 12:44:36 +0100 Subject: [PATCH 46/64] Fix usage of flip() and flop() in Flip manipulator --- src/Manipulators/Flip.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Manipulators/Flip.php b/src/Manipulators/Flip.php index a9203b7a..e676369d 100644 --- a/src/Manipulators/Flip.php +++ b/src/Manipulators/Flip.php @@ -20,10 +20,16 @@ public function run(ImageInterface $image): ImageInterface { if ($flip = $this->getFlip()) { if ('both' === $flip) { - return $image->flip('h')->flip('v'); + return $image->flip()->flop(); } - return $image->flip($flip); + if ('h' === $flip) { + return $image->flip(); + } + + if ('v' === $flip) { + return $image->flop(); + } } return $image; From 13ac3da1ceaaf36945fb7b46a3af16fb7506c8e8 Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 25 Jan 2024 12:46:26 +0100 Subject: [PATCH 47/64] fix type casting errors --- src/Manipulators/Border.php | 2 +- src/Manipulators/Size.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Manipulators/Border.php b/src/Manipulators/Border.php index 030ef0d5..75be4345 100644 --- a/src/Manipulators/Border.php +++ b/src/Manipulators/Border.php @@ -148,7 +148,7 @@ function (RectangleFactory $rectangle) use ($image, $width, $color) { (int) round($image->width() - $width), (int) round($image->height() - $width), ); - $rectangle->border($color, $width); + $rectangle->border($color, intval($width)); } ); } diff --git a/src/Manipulators/Size.php b/src/Manipulators/Size.php index c6c78f9e..2358e533 100644 --- a/src/Manipulators/Size.php +++ b/src/Manipulators/Size.php @@ -70,7 +70,7 @@ public function run(ImageInterface $image): ImageInterface list($width, $height) = $this->applyDpr($width, $height, $dpr); list($width, $height) = $this->limitImageSize($width, $height); - if ((int) $width !== (int) $image->width() || (int) $height !== (int) $image->height() || 1.0 !== $this->getCrop()[2]) { + if ((int) $width !== $image->width() || (int) $height !== $image->height() || 1.0 !== $this->getCrop()[2]) { $image = $this->runResize($image, $fit, (int) $width, (int) $height); } From 8000a817a39ff9bd58702b8dfcee540b4c90a3ee Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 25 Jan 2024 14:18:22 +0100 Subject: [PATCH 48/64] Fix opacity of Watermark manipulator --- src/Manipulators/Watermark.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Manipulators/Watermark.php b/src/Manipulators/Watermark.php index 82f180e8..afb06b90 100644 --- a/src/Manipulators/Watermark.php +++ b/src/Manipulators/Watermark.php @@ -122,11 +122,7 @@ public function run(ImageInterface $image): ImageInterface ]); $watermark = $size->run($watermark); - if ($markalpha < 100) { - $watermark->opacity($markalpha); - } - - $image->place($watermark, $markpos, intval($markx), intval($marky)); + $image->place($watermark, $markpos, intval($markx), intval($marky), $markalpha); } return $image; From 155587c518ec3b371af1d60333693e313125f2c5 Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 25 Jan 2024 14:30:51 +0100 Subject: [PATCH 49/64] Fix return type of watermark --- src/Manipulators/Watermark.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Manipulators/Watermark.php b/src/Manipulators/Watermark.php index afb06b90..552eb7fd 100644 --- a/src/Manipulators/Watermark.php +++ b/src/Manipulators/Watermark.php @@ -159,11 +159,17 @@ public function getImage(ImageInterface $image): ?ImageInterface if ($this->watermarks->fileExists($path)) { $source = $this->watermarks->read($path); - return $image->driver()->handleInput($source); + $mark = $image->driver()->handleInput($source); } } catch (FilesystemV2Exception $exception) { throw new FilesystemException('Could not read the image `'.$path.'`.'); } + + if (! $mark instanceof ImageInterface) { + return null; + } + + return $mark; } /** From eb917be3a78c46684a9f5f6bf60b7b908fad4d81 Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 25 Jan 2024 14:32:05 +0100 Subject: [PATCH 50/64] Fix code style --- src/Manipulators/Watermark.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Manipulators/Watermark.php b/src/Manipulators/Watermark.php index 552eb7fd..a93427cf 100644 --- a/src/Manipulators/Watermark.php +++ b/src/Manipulators/Watermark.php @@ -165,7 +165,7 @@ public function getImage(ImageInterface $image): ?ImageInterface throw new FilesystemException('Could not read the image `'.$path.'`.'); } - if (! $mark instanceof ImageInterface) { + if (!$mark instanceof ImageInterface) { return null; } From 810cdc8a62d42e88356fa8dd4e067fc56c61a7a2 Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 25 Jan 2024 15:43:46 +0100 Subject: [PATCH 51/64] Fix flip and flop see https://github.com/Intervention/docs/pull/34 --- src/Manipulators/Flip.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Manipulators/Flip.php b/src/Manipulators/Flip.php index e676369d..0f66c93d 100644 --- a/src/Manipulators/Flip.php +++ b/src/Manipulators/Flip.php @@ -23,11 +23,11 @@ public function run(ImageInterface $image): ImageInterface return $image->flip()->flop(); } - if ('h' === $flip) { + if ('v' === $flip) { return $image->flip(); } - if ('v' === $flip) { + if ('h' === $flip) { return $image->flop(); } } From a3fd0901fdb97b8a33e0d5368ad6c7682c50ad76 Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 25 Jan 2024 15:47:02 +0100 Subject: [PATCH 52/64] Fix code style --- src/Api/Api.php | 1 - src/Manipulators/Background.php | 1 - tests/Manipulators/BackgroundTest.php | 6 +++--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Api/Api.php b/src/Api/Api.php index 3c4e4a79..f8483452 100644 --- a/src/Api/Api.php +++ b/src/Api/Api.php @@ -3,7 +3,6 @@ namespace League\Glide\Api; use Intervention\Image\ImageManager; -use League\Glide\Manipulators\Encode; use League\Glide\Manipulators\ManipulatorInterface; class Api implements ApiInterface diff --git a/src/Manipulators/Background.php b/src/Manipulators/Background.php index ed1b7b6a..ee527d53 100644 --- a/src/Manipulators/Background.php +++ b/src/Manipulators/Background.php @@ -2,7 +2,6 @@ namespace League\Glide\Manipulators; -use Intervention\Image\ImageManager; use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Origin; use League\Glide\Manipulators\Helpers\Color; diff --git a/tests/Manipulators/BackgroundTest.php b/tests/Manipulators/BackgroundTest.php index 8f51844b..6276434a 100644 --- a/tests/Manipulators/BackgroundTest.php +++ b/tests/Manipulators/BackgroundTest.php @@ -30,9 +30,9 @@ public function testRun() $mock->shouldReceive('height')->andReturn(100)->once(); $mock->shouldReceive('origin')->andReturn($originMock)->once(); - $mock->shouldReceive('driver')->andReturn(\Mockery::mock(DriverInterface::class, function ($mock) use ($originMock) { - $mock->shouldReceive('createImage')->with(100, 100)->andReturn(\Mockery::mock(ImageInterface::class, function ($mock) use ($originMock) { - $mock->shouldReceive('fill')->with('rgba(0, 0, 0, 1)')->andReturn(\Mockery::mock(ImageInterface::class, function ($mock) use ($originMock) { + $mock->shouldReceive('driver')->andReturn(\Mockery::mock(DriverInterface::class, function ($mock) { + $mock->shouldReceive('createImage')->with(100, 100)->andReturn(\Mockery::mock(ImageInterface::class, function ($mock) { + $mock->shouldReceive('fill')->with('rgba(0, 0, 0, 1)')->andReturn(\Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('setOrigin')->withArgs(function ($arg1) { return $arg1 instanceof Origin; })->andReturn($mock)->once(); From 9d10e69df78247e7cd0c3237373ae9235601bd31 Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 25 Jan 2024 16:22:17 +0100 Subject: [PATCH 53/64] Fix ApiTest --- tests/Api/ApiTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/Api/ApiTest.php b/tests/Api/ApiTest.php index 6785bf87..da3b58cc 100644 --- a/tests/Api/ApiTest.php +++ b/tests/Api/ApiTest.php @@ -3,6 +3,7 @@ namespace League\Glide\Api; use Intervention\Image\ImageManager; +use Intervention\Image\Interfaces\EncodedImageInterface; use Intervention\Image\Interfaces\ImageInterface; use League\Glide\Manipulators\ManipulatorInterface; use PHPUnit\Framework\TestCase; @@ -60,7 +61,9 @@ public function testGetManipulators() public function testRun() { $image = \Mockery::mock(ImageInterface::class, function ($mock) { - $mock->shouldReceive('getEncoded')->andReturn('encoded'); + $mock->shouldReceive('encodeByMediaType')->andReturn(\Mockery::mock(EncodedImageInterface::class, function ($mock) { + $mock->shouldReceive('toString')->andReturn('encoded'); + })); }); $manager = ImageManager::gd(); From 66ad315c190fd583e2b97206d9e87f6d056b9fac Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 25 Jan 2024 16:22:35 +0100 Subject: [PATCH 54/64] Fix Border and Flip test --- tests/Manipulators/BorderTest.php | 6 +++--- tests/Manipulators/FlipTest.php | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/tests/Manipulators/BorderTest.php b/tests/Manipulators/BorderTest.php index 9689df63..211275b5 100644 --- a/tests/Manipulators/BorderTest.php +++ b/tests/Manipulators/BorderTest.php @@ -94,7 +94,7 @@ public function testRunOverlay() $image = \Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('width')->andReturn(100)->once(); $mock->shouldReceive('height')->andReturn(100)->once(); - $mock->shouldReceive('rectangle')->with(5, 5, 95, 95, \Mockery::on(function ($closure) { + $mock->shouldReceive('drawRectangle')->with(5, 5, \Mockery::on(function ($closure) { return true; }))->andReturn($mock)->once(); }); @@ -111,7 +111,7 @@ public function testRunShrink() $mock->shouldReceive('width')->andReturn(100)->once(); $mock->shouldReceive('height')->andReturn(100)->once(); $mock->shouldReceive('resize')->with(80, 80)->andReturn($mock)->once(); - $mock->shouldReceive('resizeCanvas')->with(20, 20, 'center', true, 'rgba(0, 0, 0, 0.5)')->andReturn($mock)->once(); + $mock->shouldReceive('resizeCanvasRelative')->with(20, 20, 'rgba(0, 0, 0, 0.5)', 'center')->andReturn($mock)->once(); }); $border = new Border(); @@ -123,7 +123,7 @@ public function testRunShrink() public function testRunExpand() { $image = \Mockery::mock(ImageInterface::class, function ($mock) { - $mock->shouldReceive('resizeCanvas')->with(20, 20, 'center', true, 'rgba(0, 0, 0, 0.5)')->andReturn($mock)->once(); + $mock->shouldReceive('resizeCanvasRelative')->with(20, 20, 'rgba(0, 0, 0, 0.5)', 'center')->andReturn($mock)->once(); }); $border = new Border(); diff --git a/tests/Manipulators/FlipTest.php b/tests/Manipulators/FlipTest.php index e923cf8f..aa7fec15 100644 --- a/tests/Manipulators/FlipTest.php +++ b/tests/Manipulators/FlipTest.php @@ -27,8 +27,8 @@ public function testCreateInstance() public function testRun() { $image = \Mockery::mock(ImageInterface::class, function ($mock) { - $mock->shouldReceive('flip')->andReturn($mock)->with('h')->once(); - $mock->shouldReceive('flip')->andReturn($mock)->with('v')->once(); + $mock->shouldReceive('flip')->andReturn($mock)->once(); + $mock->shouldReceive('flop')->andReturn($mock)->once(); }); $this->assertInstanceOf( @@ -42,6 +42,19 @@ public function testRun() ); } + public function testRunBoth() + { + $image = \Mockery::mock(ImageInterface::class, function ($mock) { + $mock->shouldReceive('flip')->andReturn($mock)->once(); + $mock->shouldReceive('flop')->andReturn($mock)->once(); + }); + + $this->assertInstanceOf( + ImageInterface::class, + $this->manipulator->setParams(['flip' => 'both'])->run($image) + ); + } + public function testGetFlip() { $this->assertSame('h', $this->manipulator->setParams(['flip' => 'h'])->getFlip()); From 81144ef97e82438d1ad69c8e322ed889e40b0b88 Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 25 Jan 2024 16:37:00 +0100 Subject: [PATCH 55/64] Require at least intervention/image v3.2 MediaTypeEncoder was introduced in 3.2.0 see https://github.com/Intervention/image/commit/04faec22a656652c123f93c75ef04b9a5def5978 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 29d60521..ef252063 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ ], "require": { "php": "^8.1", - "intervention/image": "^3", + "intervention/image": "^3.2", "league/flysystem": "^2.0|^3.0", "psr/http-message": "^1.0|^2.0" }, From 6bc9dec5bef19ac8bdf19c85771f58d0d5ea936f Mon Sep 17 00:00:00 2001 From: ADmad Date: Thu, 25 Jan 2024 22:12:50 +0530 Subject: [PATCH 56/64] Fix border test. --- tests/Manipulators/BorderTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/Manipulators/BorderTest.php b/tests/Manipulators/BorderTest.php index 211275b5..15deff9b 100644 --- a/tests/Manipulators/BorderTest.php +++ b/tests/Manipulators/BorderTest.php @@ -2,6 +2,7 @@ namespace League\Glide\Manipulators; +use Intervention\Image\Geometry\Factories\RectangleFactory; use Intervention\Image\Interfaces\ImageInterface; use PHPUnit\Framework\TestCase; @@ -95,6 +96,13 @@ public function testRunOverlay() $mock->shouldReceive('width')->andReturn(100)->once(); $mock->shouldReceive('height')->andReturn(100)->once(); $mock->shouldReceive('drawRectangle')->with(5, 5, \Mockery::on(function ($closure) { + $mock2 = \Mockery::mock(RectangleFactory::class, function ($mock2) { + $mock2->shouldReceive('size')->once(); + $mock2->shouldReceive('border')->once(); + }); + + $closure($mock2); + return true; }))->andReturn($mock)->once(); }); From fadf2d37bcbebba28da20a36f4ee264bdb850f8e Mon Sep 17 00:00:00 2001 From: Art4 Date: Fri, 26 Jan 2024 08:54:18 +0100 Subject: [PATCH 57/64] Fix size=contain --- src/Manipulators/Size.php | 2 +- tests/Manipulators/SizeTest.php | 10 +++------- tests/Manipulators/WatermarkTest.php | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/Manipulators/Size.php b/src/Manipulators/Size.php index 2358e533..cee97900 100644 --- a/src/Manipulators/Size.php +++ b/src/Manipulators/Size.php @@ -278,7 +278,7 @@ public function runResize(ImageInterface $image, $fit, $width, $height): ImageIn */ public function runContainResize(ImageInterface $image, $width, $height): ImageInterface { - return $image->resize($width, $height); + return $image->scale($width, $height); } /** diff --git a/tests/Manipulators/SizeTest.php b/tests/Manipulators/SizeTest.php index c24cb4fd..f756a01d 100644 --- a/tests/Manipulators/SizeTest.php +++ b/tests/Manipulators/SizeTest.php @@ -8,14 +8,10 @@ class SizeTest extends TestCase { private $manipulator; - private $callback; public function setUp(): void { $this->manipulator = new Size(); - $this->callback = \Mockery::on(function () { - return true; - }); } public function tearDown(): void @@ -44,7 +40,7 @@ public function testRun() $image = \Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('width')->andReturn('200')->twice(); $mock->shouldReceive('height')->andReturn('200')->once(); - $mock->shouldReceive('resize')->with(100, 100)->andReturn($mock)->once(); + $mock->shouldReceive('scale')->with(100, 100)->andReturn($mock)->once(); }); $this->assertInstanceOf( @@ -152,7 +148,7 @@ public function testRunResize() $mock->shouldReceive('height')->andReturn(100)->times(4); $mock->shouldReceive('crop')->andReturn($mock)->once(); $mock->shouldReceive('resize')->with(100, 100)->andReturn($mock)->times(5); - $mock->shouldReceive('resize')->with(100, 100)->andReturn($mock)->once(); + $mock->shouldReceive('scale')->with(100, 100)->andReturn($mock)->once(); $mock->shouldReceive('resizeCanvas')->with(100, 100, 'ffffff', 'center')->andReturn($mock)->times(2); }); @@ -195,7 +191,7 @@ public function testRunResize() public function testRunContainResize() { $image = \Mockery::mock(ImageInterface::class, function ($mock) { - $mock->shouldReceive('resize')->with(100, 100)->andReturn($mock)->once(); + $mock->shouldReceive('scale')->with(100, 100)->andReturn($mock)->once(); }); $this->assertInstanceOf( diff --git a/tests/Manipulators/WatermarkTest.php b/tests/Manipulators/WatermarkTest.php index 4235066a..176686f8 100644 --- a/tests/Manipulators/WatermarkTest.php +++ b/tests/Manipulators/WatermarkTest.php @@ -57,7 +57,7 @@ public function testRun() $mock->shouldReceive('driver')->andReturn(\Mockery::mock(DriverInterface::class, function ($mock) { $mock->shouldReceive('handleInput')->with('content')->andReturn(\Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('width')->andReturn(0)->once(); - $mock->shouldReceive('resize')->once(); + $mock->shouldReceive('scale')->once(); }))->once(); }))->once(); }); From 807885406eb0def9f72f24abe67fa8975b847eb9 Mon Sep 17 00:00:00 2001 From: Art4 Date: Fri, 26 Jan 2024 16:24:45 +0100 Subject: [PATCH 58/64] Fix size=max --- src/Manipulators/Size.php | 2 +- tests/Manipulators/SizeTest.php | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Manipulators/Size.php b/src/Manipulators/Size.php index cee97900..f5a68510 100644 --- a/src/Manipulators/Size.php +++ b/src/Manipulators/Size.php @@ -292,7 +292,7 @@ public function runContainResize(ImageInterface $image, $width, $height): ImageI */ public function runMaxResize(ImageInterface $image, $width, $height): ImageInterface { - return $image->resize($width, $height); + return $image->scaleDown($width, $height); } /** diff --git a/tests/Manipulators/SizeTest.php b/tests/Manipulators/SizeTest.php index f756a01d..2bb90933 100644 --- a/tests/Manipulators/SizeTest.php +++ b/tests/Manipulators/SizeTest.php @@ -147,7 +147,8 @@ public function testRunResize() $mock->shouldReceive('width')->andReturn(100)->times(4); $mock->shouldReceive('height')->andReturn(100)->times(4); $mock->shouldReceive('crop')->andReturn($mock)->once(); - $mock->shouldReceive('resize')->with(100, 100)->andReturn($mock)->times(5); + $mock->shouldReceive('resize')->with(100, 100)->andReturn($mock)->times(3); + $mock->shouldReceive('scaleDown')->with(100, 100)->andReturn($mock)->times(2); $mock->shouldReceive('scale')->with(100, 100)->andReturn($mock)->once(); $mock->shouldReceive('resizeCanvas')->with(100, 100, 'ffffff', 'center')->andReturn($mock)->times(2); }); @@ -203,7 +204,7 @@ public function testRunContainResize() public function testRunFillResize() { $image = \Mockery::mock(ImageInterface::class, function ($mock) { - $mock->shouldReceive('resize')->with(100, 100)->andReturn($mock)->once(); + $mock->shouldReceive('scaleDown')->with(100, 100)->andReturn($mock)->once(); $mock->shouldReceive('resizeCanvas')->with(100, 100, 'ffffff', 'center')->andReturn($mock)->once(); }); @@ -216,7 +217,7 @@ public function testRunFillResize() public function testRunMaxResize() { $image = \Mockery::mock(ImageInterface::class, function ($mock) { - $mock->shouldReceive('resize')->with(100, 100)->andReturn($mock)->once(); + $mock->shouldReceive('scaleDown')->with(100, 100)->andReturn($mock)->once(); }); $this->assertInstanceOf( From 4b0a0de30b42d55cbca3aa6750580620e26d88c7 Mon Sep 17 00:00:00 2001 From: ADmad Date: Fri, 26 Jan 2024 23:18:36 +0530 Subject: [PATCH 59/64] Fix "fill-max" resize --- src/Manipulators/Size.php | 2 +- tests/Manipulators/SizeTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Manipulators/Size.php b/src/Manipulators/Size.php index f5a68510..20c96876 100644 --- a/src/Manipulators/Size.php +++ b/src/Manipulators/Size.php @@ -322,7 +322,7 @@ public function runFillResize(ImageInterface $image, $width, $height): ImageInte */ public function runFillMaxResize(ImageInterface $image, $width, $height): ImageInterface { - $image = $image->resize($width, $height); + $image = $image->scale($width, $height); return $image->resizeCanvas($width, $height, 'ffffff', 'center'); } diff --git a/tests/Manipulators/SizeTest.php b/tests/Manipulators/SizeTest.php index 2bb90933..c969c3f2 100644 --- a/tests/Manipulators/SizeTest.php +++ b/tests/Manipulators/SizeTest.php @@ -147,9 +147,9 @@ public function testRunResize() $mock->shouldReceive('width')->andReturn(100)->times(4); $mock->shouldReceive('height')->andReturn(100)->times(4); $mock->shouldReceive('crop')->andReturn($mock)->once(); - $mock->shouldReceive('resize')->with(100, 100)->andReturn($mock)->times(3); + $mock->shouldReceive('resize')->with(100, 100)->andReturn($mock)->times(2); $mock->shouldReceive('scaleDown')->with(100, 100)->andReturn($mock)->times(2); - $mock->shouldReceive('scale')->with(100, 100)->andReturn($mock)->once(); + $mock->shouldReceive('scale')->with(100, 100)->andReturn($mock)->times(2); $mock->shouldReceive('resizeCanvas')->with(100, 100, 'ffffff', 'center')->andReturn($mock)->times(2); }); From 9e28ec524a57b2a513e09363661c19abde7c771a Mon Sep 17 00:00:00 2001 From: ADmad Date: Fri, 26 Jan 2024 23:45:17 +0530 Subject: [PATCH 60/64] Simplify "fill" and "fill-max" resizing. --- src/Manipulators/Size.php | 8 ++------ tests/Manipulators/SizeTest.php | 10 +++++----- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/Manipulators/Size.php b/src/Manipulators/Size.php index 20c96876..8d551330 100644 --- a/src/Manipulators/Size.php +++ b/src/Manipulators/Size.php @@ -306,9 +306,7 @@ public function runMaxResize(ImageInterface $image, $width, $height): ImageInter */ public function runFillResize(ImageInterface $image, $width, $height): ImageInterface { - $image = $this->runMaxResize($image, $width, $height); - - return $image->resizeCanvas($width, $height, 'ffffff', 'center'); + return $image->pad($width, $height); } /** @@ -322,9 +320,7 @@ public function runFillResize(ImageInterface $image, $width, $height): ImageInte */ public function runFillMaxResize(ImageInterface $image, $width, $height): ImageInterface { - $image = $image->scale($width, $height); - - return $image->resizeCanvas($width, $height, 'ffffff', 'center'); + return $image->contain($width, $height); } /** diff --git a/tests/Manipulators/SizeTest.php b/tests/Manipulators/SizeTest.php index c969c3f2..d460b7d7 100644 --- a/tests/Manipulators/SizeTest.php +++ b/tests/Manipulators/SizeTest.php @@ -147,10 +147,11 @@ public function testRunResize() $mock->shouldReceive('width')->andReturn(100)->times(4); $mock->shouldReceive('height')->andReturn(100)->times(4); $mock->shouldReceive('crop')->andReturn($mock)->once(); + $mock->shouldReceive('contain')->andReturn($mock)->once(); $mock->shouldReceive('resize')->with(100, 100)->andReturn($mock)->times(2); - $mock->shouldReceive('scaleDown')->with(100, 100)->andReturn($mock)->times(2); - $mock->shouldReceive('scale')->with(100, 100)->andReturn($mock)->times(2); - $mock->shouldReceive('resizeCanvas')->with(100, 100, 'ffffff', 'center')->andReturn($mock)->times(2); + $mock->shouldReceive('pad')->andReturn($mock)->once(); + $mock->shouldReceive('scaleDown')->with(100, 100)->andReturn($mock)->times(1); + $mock->shouldReceive('scale')->with(100, 100)->andReturn($mock)->times(1); }); $this->assertInstanceOf( @@ -204,8 +205,7 @@ public function testRunContainResize() public function testRunFillResize() { $image = \Mockery::mock(ImageInterface::class, function ($mock) { - $mock->shouldReceive('scaleDown')->with(100, 100)->andReturn($mock)->once(); - $mock->shouldReceive('resizeCanvas')->with(100, 100, 'ffffff', 'center')->andReturn($mock)->once(); + $mock->shouldReceive('pad')->with(100, 100)->andReturn($mock)->once(); }); $this->assertInstanceOf( From 1aea4e6567d0af4f673e353ed21bbe54644b1349 Mon Sep 17 00:00:00 2001 From: ADmad Date: Fri, 26 Jan 2024 23:59:59 +0530 Subject: [PATCH 61/64] Fix crop fit --- src/Manipulators/Size.php | 2 +- tests/Manipulators/SizeTest.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Manipulators/Size.php b/src/Manipulators/Size.php index 8d551330..298f10a8 100644 --- a/src/Manipulators/Size.php +++ b/src/Manipulators/Size.php @@ -352,7 +352,7 @@ public function runCropResize(ImageInterface $image, $width, $height): ImageInte $zoom = $this->getCrop()[2]; - $image->resize($resize_width * $zoom, $resize_height * $zoom); + $image->scale((int) ($resize_width * $zoom), (int) ($resize_height * $zoom)); list($offset_x, $offset_y) = $this->resolveCropOffset($image, $width, $height); diff --git a/tests/Manipulators/SizeTest.php b/tests/Manipulators/SizeTest.php index d460b7d7..f8fbdeeb 100644 --- a/tests/Manipulators/SizeTest.php +++ b/tests/Manipulators/SizeTest.php @@ -148,10 +148,10 @@ public function testRunResize() $mock->shouldReceive('height')->andReturn(100)->times(4); $mock->shouldReceive('crop')->andReturn($mock)->once(); $mock->shouldReceive('contain')->andReturn($mock)->once(); - $mock->shouldReceive('resize')->with(100, 100)->andReturn($mock)->times(2); + $mock->shouldReceive('resize')->with(100, 100)->andReturn($mock)->once(); $mock->shouldReceive('pad')->andReturn($mock)->once(); $mock->shouldReceive('scaleDown')->with(100, 100)->andReturn($mock)->times(1); - $mock->shouldReceive('scale')->with(100, 100)->andReturn($mock)->times(1); + $mock->shouldReceive('scale')->with(100, 100)->andReturn($mock)->times(2); }); $this->assertInstanceOf( @@ -243,7 +243,7 @@ public function testRunCropResize() $image = \Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('width')->andReturn(100)->times(4); $mock->shouldReceive('height')->andReturn(100)->times(4); - $mock->shouldReceive('resize')->with(100, 100)->andReturn($mock)->once(); + $mock->shouldReceive('scale')->with(100, 100)->andReturn($mock)->once(); $mock->shouldReceive('crop')->with(100, 100, 0, 0)->andReturn($mock)->once(); }); @@ -288,7 +288,7 @@ public function testResizeDoesRunWhenDimensionsAreTheSameAndTheCropZoomIsNotDefa $image = \Mockery::mock(ImageInterface::class, function ($mock) { $mock->shouldReceive('width')->andReturn(100); $mock->shouldReceive('height')->andReturn(100); - $mock->shouldReceive('resize')->once(); + $mock->shouldReceive('scale')->once(); $mock->shouldReceive('crop')->once()->andReturn($mock); }); From b3bde5d1005ae807357e47626edb1dc4570d9126 Mon Sep 17 00:00:00 2001 From: ADmad Date: Sat, 27 Jan 2024 00:11:20 +0530 Subject: [PATCH 62/64] Fix argument type --- src/Manipulators/Border.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Manipulators/Border.php b/src/Manipulators/Border.php index 75be4345..601b68ac 100644 --- a/src/Manipulators/Border.php +++ b/src/Manipulators/Border.php @@ -59,8 +59,8 @@ public function getBorder(ImageInterface $image): ?array $values = explode(',', $this->border); $width = $this->getWidth($image, $this->getDpr(), isset($values[0]) ? $values[0] : null); - $color = $this->getColor(isset($values[1]) ? $values[1] : null); - $method = $this->getMethod(isset($values[2]) ? $values[2] : null); + $color = $this->getColor(isset($values[1]) ? $values[1] : 'ffffff'); + $method = $this->getMethod(isset($values[2]) ? $values[2] : 'overlay'); if ($width) { return [$width, $color, $method]; @@ -90,7 +90,7 @@ public function getWidth(ImageInterface $image, $dpr, $width): ?float * * @return string The formatted color. */ - public function getColor($color) + public function getColor(string $color) { return (new Color($color))->formatted(); } @@ -102,7 +102,7 @@ public function getColor($color) * * @return string The resolved border method. */ - public function getMethod($method) + public function getMethod(string $method) { if (!in_array($method, ['expand', 'shrink', 'overlay'], true)) { return 'overlay'; From 2c27102254903fcbaefe38cd30dace1816a55d21 Mon Sep 17 00:00:00 2001 From: ADmad Date: Sat, 27 Jan 2024 00:16:33 +0530 Subject: [PATCH 63/64] Round the values before casting to int --- src/Manipulators/Size.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Manipulators/Size.php b/src/Manipulators/Size.php index 298f10a8..619f9458 100644 --- a/src/Manipulators/Size.php +++ b/src/Manipulators/Size.php @@ -352,7 +352,7 @@ public function runCropResize(ImageInterface $image, $width, $height): ImageInte $zoom = $this->getCrop()[2]; - $image->scale((int) ($resize_width * $zoom), (int) ($resize_height * $zoom)); + $image->scale((int) round($resize_width * $zoom), (int) round($resize_height * $zoom)); list($offset_x, $offset_y) = $this->resolveCropOffset($image, $width, $height); From cfddb6a7fe24b65b918c62eb7d2a07e1bd059a86 Mon Sep 17 00:00:00 2001 From: Art4 Date: Sat, 27 Jan 2024 00:43:55 +0100 Subject: [PATCH 64/64] Uncommend Encode manipulator --- src/ServerFactory.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ServerFactory.php b/src/ServerFactory.php index dce1904e..2ee849e0 100644 --- a/src/ServerFactory.php +++ b/src/ServerFactory.php @@ -278,8 +278,7 @@ public function getManipulators() new Watermark($this->getWatermarks(), $this->getWatermarksPathPrefix() ?: ''), new Background(), new Border(), - // TODO: Encoding was moved to Api::run() - // new Encode(), + new Encode(), ]; }