1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-29 16:50:07 +02:00

Add configuration object

This commit is contained in:
Oliver Vogel
2024-05-06 17:28:12 +02:00
parent cf0291f9c1
commit 93fcd10287
5 changed files with 72 additions and 5 deletions

32
src/Config.php Normal file
View File

@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
namespace Intervention\Image;
use Intervention\Image\Interfaces\ConfigInterface;
class Config implements ConfigInterface
{
public function __construct(
protected bool $autoOrientate = true,
protected bool $decodeAnimation = true,
protected mixed $blendingColor = 'ffffffff',
) {
}
public function decodeAnimation(): bool
{
return $this->decodeAnimation;
}
public function autoOrientate(): bool
{
return $this->autoOrientate;
}
public function blendingColor(): mixed
{
return $this->blendingColor;
}
}

View File

@@ -4,11 +4,13 @@ declare(strict_types=1);
namespace Intervention\Image\Drivers; namespace Intervention\Image\Drivers;
use Intervention\Image\Config;
use Intervention\Image\Exceptions\DriverException; use Intervention\Image\Exceptions\DriverException;
use Intervention\Image\Exceptions\NotSupportedException; use Intervention\Image\Exceptions\NotSupportedException;
use Intervention\Image\InputHandler; use Intervention\Image\InputHandler;
use Intervention\Image\Interfaces\AnalyzerInterface; use Intervention\Image\Interfaces\AnalyzerInterface;
use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ConfigInterface;
use Intervention\Image\Interfaces\DecoderInterface; use Intervention\Image\Interfaces\DecoderInterface;
use Intervention\Image\Interfaces\DriverInterface; use Intervention\Image\Interfaces\DriverInterface;
use Intervention\Image\Interfaces\EncoderInterface; use Intervention\Image\Interfaces\EncoderInterface;
@@ -21,13 +23,25 @@ use ReflectionClass;
abstract class AbstractDriver implements DriverInterface abstract class AbstractDriver implements DriverInterface
{ {
/** /**
* @param ConfigInterface $config
* @throws DriverException * @throws DriverException
* @return void
*/ */
public function __construct() public function __construct(protected ConfigInterface $config = new Config())
{ {
$this->checkHealth(); $this->checkHealth();
} }
/**
* {@inheritdoc}
*
* @see DriverInterface::config()
*/
public function config(): ConfigInterface
{
return $this->config;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
* *

View File

@@ -40,22 +40,24 @@ final class ImageManager implements ImageManagerInterface
* Create image manager with GD driver * Create image manager with GD driver
* *
* @link https://image.intervention.io/v3/basics/image-manager#static-gd-driver-constructor * @link https://image.intervention.io/v3/basics/image-manager#static-gd-driver-constructor
* @param mixed $options
* @return ImageManager * @return ImageManager
*/ */
public static function gd(): self public static function gd(mixed ...$options): self
{ {
return self::withDriver(GdDriver::class); return self::withDriver(new GdDriver(new Config(...$options)));
} }
/** /**
* Create image manager with Imagick driver * Create image manager with Imagick driver
* *
* @link https://image.intervention.io/v3/basics/image-manager#static-imagick-driver-constructor * @link https://image.intervention.io/v3/basics/image-manager#static-imagick-driver-constructor
* @param mixed $options
* @return ImageManager * @return ImageManager
*/ */
public static function imagick(): self public static function imagick(mixed ...$options): self
{ {
return self::withDriver(ImagickDriver::class); return self::withDriver(new ImagickDriver(new Config(...$options)));
} }
/** /**

View File

@@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
interface ConfigInterface
{
public function decodeAnimation(): bool;
public function autoOrientate(): bool;
public function blendingColor(): mixed;
}

View File

@@ -20,6 +20,13 @@ interface DriverInterface
*/ */
public function id(): string; public function id(): string;
/**
* Get driver configuration
*
* @return ConfigInterface
*/
public function config(): ConfigInterface;
/** /**
* Resolve given object into a specialized version for the current driver * Resolve given object into a specialized version for the current driver
* *