diff --git a/src/Config.php b/src/Config.php index da8edf01..0bd1b3b7 100644 --- a/src/Config.php +++ b/src/Config.php @@ -14,13 +14,16 @@ class Config * @param bool $autoOrientation * @param bool $decodeAnimation * @param mixed $blendingColor + * @param bool $strip * @return void */ public function __construct( public bool $autoOrientation = true, public bool $decodeAnimation = true, public mixed $blendingColor = 'ffffff', + public bool $strip = false, ) { + // } /** diff --git a/src/Drivers/Imagick/Encoders/AvifEncoder.php b/src/Drivers/Imagick/Encoders/AvifEncoder.php index 4cb5ce8a..64cb4aeb 100644 --- a/src/Drivers/Imagick/Encoders/AvifEncoder.php +++ b/src/Drivers/Imagick/Encoders/AvifEncoder.php @@ -19,7 +19,8 @@ public function encode(ImageInterface $image): EncodedImageInterface $format = 'AVIF'; $compression = Imagick::COMPRESSION_ZIP; - if ($this->strip) { + // strip meta data + if ($this->strip || (is_null($this->strip) && $this->driver()->config()->strip)) { $image->modify(new StripMetaModifier()); } diff --git a/src/Drivers/Imagick/Encoders/HeicEncoder.php b/src/Drivers/Imagick/Encoders/HeicEncoder.php index 9decb20c..471edb1f 100644 --- a/src/Drivers/Imagick/Encoders/HeicEncoder.php +++ b/src/Drivers/Imagick/Encoders/HeicEncoder.php @@ -17,7 +17,8 @@ public function encode(ImageInterface $image): EncodedImageInterface { $format = 'HEIC'; - if ($this->strip) { + // strip meta data + if ($this->strip || (is_null($this->strip) && $this->driver()->config()->strip)) { $image->modify(new StripMetaModifier()); } diff --git a/src/Drivers/Imagick/Encoders/Jpeg2000Encoder.php b/src/Drivers/Imagick/Encoders/Jpeg2000Encoder.php index 1c65c42e..16f6593b 100644 --- a/src/Drivers/Imagick/Encoders/Jpeg2000Encoder.php +++ b/src/Drivers/Imagick/Encoders/Jpeg2000Encoder.php @@ -19,7 +19,8 @@ public function encode(ImageInterface $image): EncodedImageInterface $format = 'JP2'; $compression = Imagick::COMPRESSION_JPEG; - if ($this->strip) { + // strip meta data + if ($this->strip || (is_null($this->strip) && $this->driver()->config()->strip)) { $image->modify(new StripMetaModifier()); } diff --git a/src/Drivers/Imagick/Encoders/JpegEncoder.php b/src/Drivers/Imagick/Encoders/JpegEncoder.php index 9ddc3538..e2365f3c 100644 --- a/src/Drivers/Imagick/Encoders/JpegEncoder.php +++ b/src/Drivers/Imagick/Encoders/JpegEncoder.php @@ -31,7 +31,8 @@ public function encode(ImageInterface $image): EncodedImageInterface // possible full transparent colors as black $background->setColorValue(Imagick::COLOR_ALPHA, 1); - if ($this->strip) { + // strip meta data + if ($this->strip || (is_null($this->strip) && $this->driver()->config()->strip)) { $image->modify(new StripMetaModifier()); } diff --git a/src/Drivers/Imagick/Encoders/TiffEncoder.php b/src/Drivers/Imagick/Encoders/TiffEncoder.php index f0d744f9..46e66536 100644 --- a/src/Drivers/Imagick/Encoders/TiffEncoder.php +++ b/src/Drivers/Imagick/Encoders/TiffEncoder.php @@ -17,7 +17,8 @@ public function encode(ImageInterface $image): EncodedImageInterface { $format = 'TIFF'; - if ($this->strip) { + // strip meta data + if ($this->strip || (is_null($this->strip) && $this->driver()->config()->strip)) { $image->modify(new StripMetaModifier()); } diff --git a/src/Drivers/Imagick/Encoders/WebpEncoder.php b/src/Drivers/Imagick/Encoders/WebpEncoder.php index d986c1e1..b65be3bc 100644 --- a/src/Drivers/Imagick/Encoders/WebpEncoder.php +++ b/src/Drivers/Imagick/Encoders/WebpEncoder.php @@ -20,7 +20,8 @@ public function encode(ImageInterface $image): EncodedImageInterface $format = 'WEBP'; $compression = Imagick::COMPRESSION_ZIP; - if ($this->strip) { + // strip meta data + if ($this->strip || (is_null($this->strip) && $this->driver()->config()->strip)) { $image->modify(new StripMetaModifier()); } diff --git a/src/Encoders/AvifEncoder.php b/src/Encoders/AvifEncoder.php index b6d3277c..a1a4a8dc 100644 --- a/src/Encoders/AvifEncoder.php +++ b/src/Encoders/AvifEncoder.php @@ -12,12 +12,13 @@ class AvifEncoder extends SpecializableEncoder * Create new encoder object * * @param int $quality - * @param bool $strip + * @param null|bool $strip * @return void */ public function __construct( public int $quality = self::DEFAULT_QUALITY, - public bool $strip = false + public ?bool $strip = null ) { + // } } diff --git a/src/Encoders/BmpEncoder.php b/src/Encoders/BmpEncoder.php index 2d25da20..46dbc9f5 100644 --- a/src/Encoders/BmpEncoder.php +++ b/src/Encoders/BmpEncoder.php @@ -10,5 +10,6 @@ class BmpEncoder extends SpecializableEncoder { public function __construct() { + // } } diff --git a/src/Encoders/GifEncoder.php b/src/Encoders/GifEncoder.php index 65f0224f..f088c759 100644 --- a/src/Encoders/GifEncoder.php +++ b/src/Encoders/GifEncoder.php @@ -16,5 +16,6 @@ class GifEncoder extends SpecializableEncoder */ public function __construct(public bool $interlaced = false) { + // } } diff --git a/src/Encoders/HeicEncoder.php b/src/Encoders/HeicEncoder.php index 41df1e36..c4f87b17 100644 --- a/src/Encoders/HeicEncoder.php +++ b/src/Encoders/HeicEncoder.php @@ -12,12 +12,13 @@ class HeicEncoder extends SpecializableEncoder * Create new encoder object * * @param int $quality - * @param bool $strip + * @param null|bool $strip * @return void */ public function __construct( public int $quality = self::DEFAULT_QUALITY, - public bool $strip = false + public ?bool $strip = null ) { + // } } diff --git a/src/Encoders/Jpeg2000Encoder.php b/src/Encoders/Jpeg2000Encoder.php index 0d6dc86c..65341d5b 100644 --- a/src/Encoders/Jpeg2000Encoder.php +++ b/src/Encoders/Jpeg2000Encoder.php @@ -12,12 +12,13 @@ class Jpeg2000Encoder extends SpecializableEncoder * Create new encoder object * * @param int $quality - * @param bool $strip + * @param null|bool $strip * @return void */ public function __construct( public int $quality = self::DEFAULT_QUALITY, - public bool $strip = false + public ?bool $strip = null ) { + // } } diff --git a/src/Encoders/JpegEncoder.php b/src/Encoders/JpegEncoder.php index 5598d00a..fc05e9c7 100644 --- a/src/Encoders/JpegEncoder.php +++ b/src/Encoders/JpegEncoder.php @@ -13,13 +13,14 @@ class JpegEncoder extends SpecializableEncoder * * @param int $quality * @param bool $progressive - * @param bool $strip + * @param null|bool $strip * @return void */ public function __construct( public int $quality = self::DEFAULT_QUALITY, public bool $progressive = false, - public bool $strip = false + public ?bool $strip = null ) { + // } } diff --git a/src/Encoders/PngEncoder.php b/src/Encoders/PngEncoder.php index b3376e0d..c2530278 100644 --- a/src/Encoders/PngEncoder.php +++ b/src/Encoders/PngEncoder.php @@ -17,5 +17,6 @@ class PngEncoder extends SpecializableEncoder */ public function __construct(public bool $interlaced = false, public bool $indexed = false) { + // } } diff --git a/src/Encoders/TiffEncoder.php b/src/Encoders/TiffEncoder.php index 2ae8e860..4ef7a8b1 100644 --- a/src/Encoders/TiffEncoder.php +++ b/src/Encoders/TiffEncoder.php @@ -12,12 +12,13 @@ class TiffEncoder extends SpecializableEncoder * Create new encoder object * * @param int $quality - * @param bool $strip + * @param null|bool $strip * @return void */ public function __construct( public int $quality = self::DEFAULT_QUALITY, - public bool $strip = false + public ?bool $strip = null ) { + // } } diff --git a/src/Encoders/WebpEncoder.php b/src/Encoders/WebpEncoder.php index 404aea00..35143d59 100644 --- a/src/Encoders/WebpEncoder.php +++ b/src/Encoders/WebpEncoder.php @@ -12,12 +12,12 @@ class WebpEncoder extends SpecializableEncoder * Create new encoder object * * @param int $quality - * @param bool $strip + * @param null|bool $strip * @return void */ public function __construct( public int $quality = self::DEFAULT_QUALITY, - public bool $strip = false + public ?bool $strip = null ) { } } diff --git a/tests/Unit/ConfigTest.php b/tests/Unit/ConfigTest.php index 6a1683bd..06555c3a 100644 --- a/tests/Unit/ConfigTest.php +++ b/tests/Unit/ConfigTest.php @@ -24,11 +24,13 @@ public function testConstructor(): void autoOrientation: false, decodeAnimation: false, blendingColor: 'f00', + strip: true, ); $this->assertInstanceOf(Config::class, $config); $this->assertFalse($config->autoOrientation); $this->assertFalse($config->decodeAnimation); + $this->assertTrue($config->strip); $this->assertEquals('f00', $config->blendingColor); } @@ -37,12 +39,14 @@ public function testGetSetOptions(): void $config = new Config(); $this->assertTrue($config->autoOrientation); $this->assertTrue($config->decodeAnimation); + $this->assertFalse($config->strip); $this->assertEquals('ffffff', $config->blendingColor); $result = $config->setOptions( autoOrientation: false, decodeAnimation: false, blendingColor: 'f00', + strip: true, ); $this->assertFalse($config->autoOrientation); @@ -51,16 +55,19 @@ public function testGetSetOptions(): void $this->assertFalse($result->autoOrientation); $this->assertFalse($result->decodeAnimation); + $this->assertTrue($result->strip); $this->assertEquals('f00', $result->blendingColor); $result = $config->setOptions(blendingColor: '000'); $this->assertFalse($config->autoOrientation); $this->assertFalse($config->decodeAnimation); + $this->assertTrue($config->strip); $this->assertEquals('000', $config->blendingColor); $this->assertFalse($result->autoOrientation); $this->assertFalse($result->decodeAnimation); + $this->assertTrue($result->strip); $this->assertEquals('000', $result->blendingColor); } @@ -71,13 +78,16 @@ public function testSetOptionsWithArray(): void 'autoOrientation' => false, 'decodeAnimation' => false, 'blendingColor' => 'f00', + 'strip' => true, ]); $this->assertFalse($config->autoOrientation); $this->assertFalse($config->decodeAnimation); + $this->assertTrue($config->strip); $this->assertEquals('f00', $config->blendingColor); $this->assertFalse($result->autoOrientation); $this->assertFalse($result->decodeAnimation); + $this->assertTrue($result->strip); $this->assertEquals('f00', $result->blendingColor); } } diff --git a/tests/Unit/Drivers/Imagick/Encoders/AvifEncoderTest.php b/tests/Unit/Drivers/Imagick/Encoders/AvifEncoderTest.php index 59acc267..d24e5e3f 100644 --- a/tests/Unit/Drivers/Imagick/Encoders/AvifEncoderTest.php +++ b/tests/Unit/Drivers/Imagick/Encoders/AvifEncoderTest.php @@ -4,6 +4,7 @@ namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Encoders; +use Intervention\Image\Drivers\Imagick\Driver; use Intervention\Image\Drivers\Imagick\Encoders\AvifEncoder; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; @@ -17,6 +18,7 @@ public function testEncode(): void { $image = $this->createTestImage(3, 2); $encoder = new AvifEncoder(10); + $encoder->setDriver(new Driver()); $result = $encoder->encode($image); $this->assertMediaType('image/avif', $result); $this->assertEquals('image/avif', $result->mimetype()); diff --git a/tests/Unit/Drivers/Imagick/Encoders/HeicEncoderTest.php b/tests/Unit/Drivers/Imagick/Encoders/HeicEncoderTest.php index 31ff3836..fb7adf46 100644 --- a/tests/Unit/Drivers/Imagick/Encoders/HeicEncoderTest.php +++ b/tests/Unit/Drivers/Imagick/Encoders/HeicEncoderTest.php @@ -4,6 +4,7 @@ namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Encoders; +use Intervention\Image\Drivers\Imagick\Driver; use Intervention\Image\Drivers\Imagick\Encoders\HeicEncoder; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; @@ -17,6 +18,7 @@ public function testEncode(): void { $image = $this->createTestImage(3, 2); $encoder = new HeicEncoder(75); + $encoder->setDriver(new Driver()); $result = $encoder->encode($image); $this->assertMediaType('image/heic', $result); $this->assertEquals('image/heic', $result->mimetype()); diff --git a/tests/Unit/Drivers/Imagick/Encoders/Jpeg2000EncoderTest.php b/tests/Unit/Drivers/Imagick/Encoders/Jpeg2000EncoderTest.php index c9e4d0b8..353d2ef8 100644 --- a/tests/Unit/Drivers/Imagick/Encoders/Jpeg2000EncoderTest.php +++ b/tests/Unit/Drivers/Imagick/Encoders/Jpeg2000EncoderTest.php @@ -4,6 +4,7 @@ namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Encoders; +use Intervention\Image\Drivers\Imagick\Driver; use Intervention\Image\Drivers\Imagick\Encoders\Jpeg2000Encoder; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; @@ -17,6 +18,7 @@ public function testEncode(): void { $image = $this->createTestImage(3, 2); $encoder = new Jpeg2000Encoder(75); + $encoder->setDriver(new Driver()); $result = $encoder->encode($image); $this->assertMediaType('image/jp2', $result); $this->assertEquals('image/jp2', $result->mimetype()); diff --git a/tests/Unit/Drivers/Imagick/Encoders/TiffEncoderTest.php b/tests/Unit/Drivers/Imagick/Encoders/TiffEncoderTest.php index 58a5dc4e..15086631 100644 --- a/tests/Unit/Drivers/Imagick/Encoders/TiffEncoderTest.php +++ b/tests/Unit/Drivers/Imagick/Encoders/TiffEncoderTest.php @@ -4,6 +4,7 @@ namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Encoders; +use Intervention\Image\Drivers\Imagick\Driver; use Intervention\Image\Drivers\Imagick\Encoders\TiffEncoder; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; @@ -17,6 +18,7 @@ public function testEncode(): void { $image = $this->createTestImage(3, 2); $encoder = new TiffEncoder(); + $encoder->setDriver(new Driver()); $result = $encoder->encode($image); $this->assertMediaType('image/tiff', $result); $this->assertEquals('image/tiff', $result->mimetype()); diff --git a/tests/Unit/Drivers/Imagick/Encoders/WebpEncoderTest.php b/tests/Unit/Drivers/Imagick/Encoders/WebpEncoderTest.php index 18bf38f2..456fdb08 100644 --- a/tests/Unit/Drivers/Imagick/Encoders/WebpEncoderTest.php +++ b/tests/Unit/Drivers/Imagick/Encoders/WebpEncoderTest.php @@ -4,6 +4,7 @@ namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Encoders; +use Intervention\Image\Drivers\Imagick\Driver; use Intervention\Image\Drivers\Imagick\Encoders\WebpEncoder; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; @@ -17,6 +18,7 @@ public function testEncode(): void { $image = $this->createTestImage(3, 2); $encoder = new WebpEncoder(75); + $encoder->setDriver(new Driver()); $result = $encoder->encode($image); $this->assertMediaType('image/webp', $result); $this->assertEquals('image/webp', $result->mimetype());