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:
16
src/Decoders/AbstractDecoder.php
Normal file
16
src/Decoders/AbstractDecoder.php
Normal 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.');
|
||||
}
|
||||
}
|
7
src/Decoders/FilePathImageDecoder.php
Normal file
7
src/Decoders/FilePathImageDecoder.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Decoders;
|
||||
|
||||
class FilePathImageDecoder extends AbstractDecoder
|
||||
{
|
||||
}
|
@@ -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;
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -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
|
||||
{
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user