1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-22 13:32:56 +02:00

Add constants for config options

This commit is contained in:
Oliver Vogel
2024-05-10 10:26:09 +02:00
parent b79650acee
commit a086989cc9
6 changed files with 15 additions and 7 deletions

View File

@@ -9,6 +9,10 @@ use Intervention\Image\Interfaces\ConfigInterface;
class Config implements ConfigInterface
{
public const AUTO_ORIENTATION = 'autoOrientation';
public const DECODE_ANIMATION = 'decodeAnimation';
public const BLENDING_COLOR = 'blendingColor';
/**
* Create config object instance
*

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
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;
@@ -60,7 +61,7 @@ class BinaryImageDecoder extends NativeObjectDecoder implements DecoderInterface
}
// adjust image orientation
if ($this->driver()->config()->option('autoOrientation') === true) {
if ($this->driver()->config()->option(Config::AUTO_ORIENTATION) === true) {
$image->modify(new AlignRotationModifier());
}

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
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;
@@ -50,7 +51,7 @@ class FilePathImageDecoder extends NativeObjectDecoder implements DecoderInterfa
$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());
}

View File

@@ -7,6 +7,7 @@ namespace Intervention\Image\Drivers\Gd\Decoders;
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;
@@ -60,7 +61,7 @@ class NativeObjectDecoder extends AbstractDecoder
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),

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
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;
@@ -40,12 +41,12 @@ class NativeObjectDecoder extends SpecializableDecoder
);
// 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());
}

View File

@@ -408,7 +408,7 @@ final class Image implements ImageInterface
public function blendingColor(): ColorInterface
{
return $this->driver()->handleInput(
$this->driver()->config()->option('blendingColor')
$this->driver()->config()->option(Config::BLENDING_COLOR)
);
}
@@ -420,7 +420,7 @@ final class Image implements ImageInterface
public function setBlendingColor(mixed $color): ImageInterface
{
$this->driver()->config()->setOption(
'blendingColor',
Config::BLENDING_COLOR,
$this->driver()->handleInput($color)
);