Skip to content

Commit

Permalink
Add constants for config options
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed May 10, 2024
1 parent b79650a commit a086989
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/Config.php
Expand Up @@ -9,6 +9,10 @@

class Config implements ConfigInterface
{
public const AUTO_ORIENTATION = 'autoOrientation';
public const DECODE_ANIMATION = 'decodeAnimation';
public const BLENDING_COLOR = 'blendingColor';

/**
* Create config object instance
*
Expand Down
3 changes: 2 additions & 1 deletion src/Drivers/Gd/Decoders/BinaryImageDecoder.php
Expand Up @@ -4,6 +4,7 @@

namespace Intervention\Image\Drivers\Gd\Decoders;

use Intervention\Image\Config;
use Intervention\Image\Exceptions\RuntimeException;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\DecoderInterface;
Expand Down Expand Up @@ -60,7 +61,7 @@ private function decodeBinary(string $input): ImageInterface
}

// adjust image orientation
if ($this->driver()->config()->option('autoOrientation') === true) {
if ($this->driver()->config()->option(Config::AUTO_ORIENTATION) === true) {
$image->modify(new AlignRotationModifier());
}

Expand Down
3 changes: 2 additions & 1 deletion src/Drivers/Gd/Decoders/FilePathImageDecoder.php
Expand Up @@ -4,6 +4,7 @@

namespace Intervention\Image\Drivers\Gd\Decoders;

use Intervention\Image\Config;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\DecoderInterface;
Expand Down Expand Up @@ -50,7 +51,7 @@ public function decode(mixed $input): ImageInterface|ColorInterface
$image->setExif($this->extractExifData($input));

// adjust image orientation
if ($this->driver()->config()->option('autoOrientation') === true) {
if ($this->driver()->config()->option(Config::AUTO_ORIENTATION) === true) {
$image->modify(new AlignRotationModifier());
}

Expand Down
3 changes: 2 additions & 1 deletion src/Drivers/Gd/Decoders/NativeObjectDecoder.php
Expand Up @@ -7,6 +7,7 @@
use GdImage;
use Intervention\Gif\Decoder as GifDecoder;
use Intervention\Gif\Splitter as GifSplitter;
use Intervention\Image\Config;
use Intervention\Image\Drivers\Gd\Core;
use Intervention\Image\Drivers\Gd\Frame;
use Intervention\Image\Exceptions\DecoderException;
Expand Down Expand Up @@ -60,7 +61,7 @@ public function decode(mixed $input): ImageInterface|ColorInterface
protected function decodeGif(mixed $input): ImageInterface
{
// create non-animated image depending on config
if (!$this->driver()->config()->option('decodeAnimation') === true) {
if (!$this->driver()->config()->option(Config::DECODE_ANIMATION) === true) {
$native = match (true) {
$this->isGifFormat($input) => @imagecreatefromstring($input),
default => @imagecreatefromgif($input),
Expand Down
5 changes: 3 additions & 2 deletions src/Drivers/Imagick/Decoders/NativeObjectDecoder.php
Expand Up @@ -5,6 +5,7 @@
namespace Intervention\Image\Drivers\Imagick\Decoders;

use Imagick;
use Intervention\Image\Config;
use Intervention\Image\Drivers\Imagick\Core;
use Intervention\Image\Drivers\SpecializableDecoder;
use Intervention\Image\Exceptions\DecoderException;
Expand Down Expand Up @@ -40,12 +41,12 @@ public function decode(mixed $input): ImageInterface|ColorInterface
);

// discard animation depending on config
if (!$this->driver()->config()->option('decodeAnimation') === true) {
if (!$this->driver()->config()->option(Config::DECODE_ANIMATION) === true) {
$image->modify(new RemoveAnimationModifier());
}

// adjust image rotatation
if ($this->driver()->config()->option('autoOrientation') === true) {
if ($this->driver()->config()->option(Config::AUTO_ORIENTATION) === true) {
$image->modify(new AlignRotationModifier());
}

Expand Down
4 changes: 2 additions & 2 deletions src/Image.php
Expand Up @@ -408,7 +408,7 @@ public function pickColors(int $x, int $y): CollectionInterface
public function blendingColor(): ColorInterface
{
return $this->driver()->handleInput(
$this->driver()->config()->option('blendingColor')
$this->driver()->config()->option(Config::BLENDING_COLOR)
);
}

Expand All @@ -420,7 +420,7 @@ public function blendingColor(): ColorInterface
public function setBlendingColor(mixed $color): ImageInterface
{
$this->driver()->config()->setOption(
'blendingColor',
Config::BLENDING_COLOR,
$this->driver()->handleInput($color)
);

Expand Down

0 comments on commit a086989

Please sign in to comment.