1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-31 17:41:58 +02:00

Add specializable decoders

This commit is contained in:
Oliver Vogel
2023-12-31 18:19:30 +01:00
parent 047d2dda47
commit c5ad95c2c3
7 changed files with 34 additions and 4 deletions

View File

@@ -0,0 +1,16 @@
<?php
namespace Intervention\Image\Decoders;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\DecoderInterface;
use Intervention\Image\Interfaces\ImageInterface;
abstract class AbstractDecoder implements DecoderInterface
{
public function decode(mixed $input): ImageInterface|ColorInterface
{
throw new DecoderException('Object must be specialized by the driver first.');
}
}

View File

@@ -0,0 +1,7 @@
<?php
namespace Intervention\Image\Decoders;
class FilePathImageDecoder extends AbstractDecoder
{
}

View File

@@ -11,7 +11,7 @@ use Intervention\Image\Interfaces\DecoderInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Traits\CanBuildFilePointer;
abstract class AbstractDecoder implements DecoderInterface
abstract class AbstractDecoder extends DriverSpecialized implements DecoderInterface
{
use CanBuildFilePointer;

View File

@@ -3,6 +3,7 @@
namespace Intervention\Image\Drivers;
use Intervention\Image\Analyzers\AbstractAnalyzer;
use Intervention\Image\Decoders\AbstractDecoder;
use Intervention\Image\Encoders\AbstractEncoder;
use Intervention\Image\Exceptions\NotSupportedException;
use Intervention\Image\Interfaces\AnalyzerInterface;
@@ -69,6 +70,10 @@ abstract class AbstractDriver implements DriverInterface
return false;
}
if ($input instanceof AbstractDecoder) {
return false;
}
return true;
}
}

View File

@@ -103,9 +103,9 @@ class Driver extends AbstractDriver
*
* @see DriverInterface::handleInput()
*/
public function handleInput(mixed $input): ImageInterface|ColorInterface
public function handleInput(mixed $input, array $decoders = []): ImageInterface|ColorInterface
{
return (new InputHandler())->handle($input);
return (new InputHandler($decoders))->handle($input);
}
/**

View File

@@ -6,6 +6,7 @@ use Intervention\Image\Interfaces\DriverInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Drivers\Gd\Driver as GdDriver;
use Intervention\Image\Drivers\Imagick\Driver as ImagickDriver;
use Intervention\Image\Interfaces\DecoderInterface;
final class ImageManager
{

View File

@@ -40,9 +40,10 @@ interface DriverInterface
* Handle given input by decoding it to ImageInterface or ColorInterface
*
* @param mixed $input
* @param array $decoders
* @return ImageInterface|ColorInterface
*/
public function handleInput(mixed $input): ImageInterface|ColorInterface;
public function handleInput(mixed $input, array $decoders = []): ImageInterface|ColorInterface;
/**
* Return color processor for the given colorspace