Skip to content

Commit

Permalink
Enable strip meta option in global driver config
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Jan 18, 2025
1 parent d01b2ab commit 5bfcb52
Show file tree
Hide file tree
Showing 22 changed files with 55 additions and 18 deletions.
3 changes: 3 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
//
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Drivers/Imagick/Encoders/AvifEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
3 changes: 2 additions & 1 deletion src/Drivers/Imagick/Encoders/HeicEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
3 changes: 2 additions & 1 deletion src/Drivers/Imagick/Encoders/Jpeg2000Encoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
3 changes: 2 additions & 1 deletion src/Drivers/Imagick/Encoders/JpegEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
3 changes: 2 additions & 1 deletion src/Drivers/Imagick/Encoders/TiffEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
3 changes: 2 additions & 1 deletion src/Drivers/Imagick/Encoders/WebpEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
5 changes: 3 additions & 2 deletions src/Encoders/AvifEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
//
}
}
1 change: 1 addition & 0 deletions src/Encoders/BmpEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ class BmpEncoder extends SpecializableEncoder
{
public function __construct()
{
//
}
}
1 change: 1 addition & 0 deletions src/Encoders/GifEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ class GifEncoder extends SpecializableEncoder
*/
public function __construct(public bool $interlaced = false)
{
//
}
}
5 changes: 3 additions & 2 deletions src/Encoders/HeicEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
//
}
}
5 changes: 3 additions & 2 deletions src/Encoders/Jpeg2000Encoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
//
}
}
5 changes: 3 additions & 2 deletions src/Encoders/JpegEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
//
}
}
1 change: 1 addition & 0 deletions src/Encoders/PngEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ class PngEncoder extends SpecializableEncoder
*/
public function __construct(public bool $interlaced = false, public bool $indexed = false)
{
//
}
}
5 changes: 3 additions & 2 deletions src/Encoders/TiffEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
//
}
}
4 changes: 2 additions & 2 deletions src/Encoders/WebpEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
}
}
10 changes: 10 additions & 0 deletions tests/Unit/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

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

Expand All @@ -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);
}
}
2 changes: 2 additions & 0 deletions tests/Unit/Drivers/Imagick/Encoders/AvifEncoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/Drivers/Imagick/Encoders/HeicEncoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/Drivers/Imagick/Encoders/Jpeg2000EncoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/Drivers/Imagick/Encoders/TiffEncoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/Drivers/Imagick/Encoders/WebpEncoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand Down

0 comments on commit 5bfcb52

Please sign in to comment.