From 59eba7d43ab8706a78b4de421e49192f9dbcac20 Mon Sep 17 00:00:00 2001 From: Konnng Date: Wed, 24 Jan 2024 10:54:00 -0300 Subject: [PATCH 01/12] 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 30dcfa4..5dbd255 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 0ed379c318915984ad2c8136fb4a87a7eda93f81 Mon Sep 17 00:00:00 2001 From: Konnng Date: Wed, 24 Jan 2024 11:31:45 -0300 Subject: [PATCH 02/12] 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 3439859..4487120 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 e3b3dc1e8ab5c864250f905deea48676f95317cc Mon Sep 17 00:00:00 2001 From: Konnng Date: Wed, 24 Jan 2024 14:38:02 -0300 Subject: [PATCH 03/12] 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 4487120..548beae 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 04/12] 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 d0b2d16..8b7080e 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 05/12] 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 5dbd255..36e4b06 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 06/12] 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 18dc703..bcc01a5 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 07/12] 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 548beae..b730e07 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 08/12] 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 937077d..53c6fe8 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 09/12] .gitignore updated --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 74c4b85..fefeece 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 10/12] 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 fdfeb6d..2166541 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 d049a11..ba55096 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 11/12] 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 2166541..ed1b7b6 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 12/12] 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 ba55096..8f51844 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();