mirror of
https://github.com/Intervention/image.git
synced 2025-08-12 00:43:59 +02:00
Replace method AbstractDecoder::fail()
This commit is contained in:
@@ -22,7 +22,7 @@ abstract class AbstractDecoder implements DecoderInterface
|
|||||||
$decoded = $this->decode($input);
|
$decoded = $this->decode($input);
|
||||||
} catch (DecoderException $e) {
|
} catch (DecoderException $e) {
|
||||||
if (!$this->hasSuccessor()) {
|
if (!$this->hasSuccessor()) {
|
||||||
$this->fail($e->getMessage());
|
throw new DecoderException($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->successor->handle($input);
|
return $this->successor->handle($input);
|
||||||
@@ -36,11 +36,6 @@ abstract class AbstractDecoder implements DecoderInterface
|
|||||||
return $this->successor !== null;
|
return $this->successor !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function fail(string $message = 'Unable to decode given input.'): void
|
|
||||||
{
|
|
||||||
throw new DecoderException($message);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function inputType($input): AbstractType
|
protected function inputType($input): AbstractType
|
||||||
{
|
{
|
||||||
return MimeSniffer::createFromString($input)->getType();
|
return MimeSniffer::createFromString($input)->getType();
|
||||||
|
@@ -4,6 +4,7 @@ namespace Intervention\Image\Drivers\Gd\Decoders;
|
|||||||
|
|
||||||
use Intervention\Image\Drivers\Abstract\Decoders\AbstractDecoder;
|
use Intervention\Image\Drivers\Abstract\Decoders\AbstractDecoder;
|
||||||
use Intervention\Image\Drivers\Gd\Color;
|
use Intervention\Image\Drivers\Gd\Color;
|
||||||
|
use Intervention\Image\Exceptions\DecoderException;
|
||||||
use Intervention\Image\Interfaces\ColorInterface;
|
use Intervention\Image\Interfaces\ColorInterface;
|
||||||
use Intervention\Image\Interfaces\DecoderInterface;
|
use Intervention\Image\Interfaces\DecoderInterface;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
@@ -16,7 +17,7 @@ class ArrayColorDecoder extends AbstractDecoder implements DecoderInterface
|
|||||||
public function decode($input): ImageInterface|ColorInterface
|
public function decode($input): ImageInterface|ColorInterface
|
||||||
{
|
{
|
||||||
if (! $this->isValidColorArray($input)) {
|
if (! $this->isValidColorArray($input)) {
|
||||||
$this->fail();
|
throw new DecoderException('Unable to decode input');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count($input) === 3) {
|
if (count($input) === 3) {
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Intervention\Image\Drivers\Gd\Decoders;
|
namespace Intervention\Image\Drivers\Gd\Decoders;
|
||||||
|
|
||||||
|
use Intervention\Image\Exceptions\DecoderException;
|
||||||
use Intervention\Image\Interfaces\ColorInterface;
|
use Intervention\Image\Interfaces\ColorInterface;
|
||||||
use Intervention\Image\Interfaces\DecoderInterface;
|
use Intervention\Image\Interfaces\DecoderInterface;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
@@ -14,7 +15,7 @@ class Base64ImageDecoder extends BinaryImageDecoder implements DecoderInterface
|
|||||||
public function decode($input): ImageInterface|ColorInterface
|
public function decode($input): ImageInterface|ColorInterface
|
||||||
{
|
{
|
||||||
if (! $this->isValidBase64($input)) {
|
if (! $this->isValidBase64($input)) {
|
||||||
$this->fail();
|
throw new DecoderException('Unable to decode input');
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::decode(base64_decode($input));
|
return parent::decode(base64_decode($input));
|
||||||
|
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace Intervention\Image\Drivers\Gd\Decoders;
|
namespace Intervention\Image\Drivers\Gd\Decoders;
|
||||||
|
|
||||||
use GdImage;
|
|
||||||
use Intervention\Image\Collection;
|
use Intervention\Image\Collection;
|
||||||
use Intervention\Image\Drivers\Abstract\Decoders\AbstractDecoder;
|
use Intervention\Image\Drivers\Abstract\Decoders\AbstractDecoder;
|
||||||
use Intervention\Image\Drivers\Gd\Frame;
|
use Intervention\Image\Drivers\Gd\Frame;
|
||||||
@@ -10,21 +9,21 @@ use Intervention\Image\Drivers\Gd\Image;
|
|||||||
use Intervention\Image\Interfaces\ColorInterface;
|
use Intervention\Image\Interfaces\ColorInterface;
|
||||||
use Intervention\Image\Interfaces\DecoderInterface;
|
use Intervention\Image\Interfaces\DecoderInterface;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
use Intervention\MimeSniffer\MimeSniffer;
|
|
||||||
use Intervention\MimeSniffer\Types\ImageGif;
|
use Intervention\MimeSniffer\Types\ImageGif;
|
||||||
use Intervention\Gif\Decoder as GifDecoder;
|
use Intervention\Gif\Decoder as GifDecoder;
|
||||||
use Intervention\Gif\Splitter as GifSplitter;
|
use Intervention\Gif\Splitter as GifSplitter;
|
||||||
|
use Intervention\Image\Exceptions\DecoderException;
|
||||||
|
|
||||||
class BinaryImageDecoder extends AbstractDecoder implements DecoderInterface
|
class BinaryImageDecoder extends AbstractDecoder implements DecoderInterface
|
||||||
{
|
{
|
||||||
public function decode($input): ImageInterface|ColorInterface
|
public function decode($input): ImageInterface|ColorInterface
|
||||||
{
|
{
|
||||||
if (!is_string($input)) {
|
if (!is_string($input)) {
|
||||||
$this->fail();
|
throw new DecoderException('Unable to decode input');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $this->inputType($input)->isBinary()) {
|
if (! $this->inputType($input)->isBinary()) {
|
||||||
$this->fail();
|
throw new DecoderException('Unable to decode input');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_a($this->inputType($input), ImageGif::class)) {
|
if (is_a($this->inputType($input), ImageGif::class)) {
|
||||||
@@ -34,7 +33,7 @@ class BinaryImageDecoder extends AbstractDecoder implements DecoderInterface
|
|||||||
$gd = @imagecreatefromstring($input);
|
$gd = @imagecreatefromstring($input);
|
||||||
|
|
||||||
if ($gd === false) {
|
if ($gd === false) {
|
||||||
$this->fail();
|
throw new DecoderException('Unable to decode input');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! imageistruecolor($gd)) {
|
if (! imageistruecolor($gd)) {
|
||||||
|
@@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
namespace Intervention\Image\Drivers\Gd\Decoders;
|
namespace Intervention\Image\Drivers\Gd\Decoders;
|
||||||
|
|
||||||
|
use Intervention\Image\Exceptions\DecoderException;
|
||||||
use Intervention\Image\Interfaces\ColorInterface;
|
use Intervention\Image\Interfaces\ColorInterface;
|
||||||
use Intervention\Image\Interfaces\DecoderInterface;
|
use Intervention\Image\Interfaces\DecoderInterface;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
use Intervention\Image\Traits\CanDecodeDataUri;
|
use Intervention\Image\Traits\CanDecodeDataUri;
|
||||||
use Intervention\MimeSniffer\MimeSniffer;
|
|
||||||
|
|
||||||
class DataUriImageDecoder extends BinaryImageDecoder implements DecoderInterface
|
class DataUriImageDecoder extends BinaryImageDecoder implements DecoderInterface
|
||||||
{
|
{
|
||||||
@@ -15,13 +15,13 @@ class DataUriImageDecoder extends BinaryImageDecoder implements DecoderInterface
|
|||||||
public function decode($input): ImageInterface|ColorInterface
|
public function decode($input): ImageInterface|ColorInterface
|
||||||
{
|
{
|
||||||
if (!is_string($input)) {
|
if (!is_string($input)) {
|
||||||
$this->fail();
|
throw new DecoderException('Unable to decode input');
|
||||||
}
|
}
|
||||||
|
|
||||||
$uri = $this->decodeDataUri($input);
|
$uri = $this->decodeDataUri($input);
|
||||||
|
|
||||||
if (! $uri->isValid()) {
|
if (! $uri->isValid()) {
|
||||||
$this->fail();
|
throw new DecoderException('Unable to decode input');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($uri->isBase64Encoded()) {
|
if ($uri->isBase64Encoded()) {
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
namespace Intervention\Image\Drivers\Gd\Decoders;
|
namespace Intervention\Image\Drivers\Gd\Decoders;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use Intervention\Image\Exceptions\DecoderException;
|
||||||
use Intervention\Image\Interfaces\ColorInterface;
|
use Intervention\Image\Interfaces\ColorInterface;
|
||||||
use Intervention\Image\Interfaces\DecoderInterface;
|
use Intervention\Image\Interfaces\DecoderInterface;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
@@ -12,15 +13,15 @@ class FilePathImageDecoder extends BinaryImageDecoder implements DecoderInterfac
|
|||||||
public function decode($input): ImageInterface|ColorInterface
|
public function decode($input): ImageInterface|ColorInterface
|
||||||
{
|
{
|
||||||
if (! is_string($input)) {
|
if (! is_string($input)) {
|
||||||
$this->fail();
|
throw new DecoderException('Unable to decode input');
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (! @is_file($input)) {
|
if (! @is_file($input)) {
|
||||||
$this->fail();
|
throw new DecoderException('Unable to decode input');
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$this->fail();
|
throw new DecoderException('Unable to decode input');
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::decode(file_get_contents($input));
|
return parent::decode(file_get_contents($input));
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Intervention\Image\Drivers\Gd\Decoders;
|
namespace Intervention\Image\Drivers\Gd\Decoders;
|
||||||
|
|
||||||
use Intervention\Image\Drivers\Gd\Color;
|
use Intervention\Image\Exceptions\DecoderException;
|
||||||
use Intervention\Image\Interfaces\ColorInterface;
|
use Intervention\Image\Interfaces\ColorInterface;
|
||||||
use Intervention\Image\Interfaces\DecoderInterface;
|
use Intervention\Image\Interfaces\DecoderInterface;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
@@ -12,14 +12,14 @@ class HexColorDecoder extends ArrayColorDecoder implements DecoderInterface
|
|||||||
public function decode($input): ImageInterface|ColorInterface
|
public function decode($input): ImageInterface|ColorInterface
|
||||||
{
|
{
|
||||||
if (!is_string($input)) {
|
if (!is_string($input)) {
|
||||||
$this->fail();
|
throw new DecoderException('Unable to decode input');
|
||||||
}
|
}
|
||||||
|
|
||||||
$pattern = '/^#?([a-f0-9]{1,2})([a-f0-9]{1,2})([a-f0-9]{1,2})$/i';
|
$pattern = '/^#?([a-f0-9]{1,2})([a-f0-9]{1,2})([a-f0-9]{1,2})$/i';
|
||||||
$result = preg_match($pattern, $input, $matches);
|
$result = preg_match($pattern, $input, $matches);
|
||||||
|
|
||||||
if ($result !== 1) {
|
if ($result !== 1) {
|
||||||
$this->fail();
|
throw new DecoderException('Unable to decode input');
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::decode([
|
return parent::decode([
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
namespace Intervention\Image\Drivers\Gd\Decoders;
|
namespace Intervention\Image\Drivers\Gd\Decoders;
|
||||||
|
|
||||||
use Intervention\Image\Drivers\Abstract\Decoders\AbstractDecoder;
|
use Intervention\Image\Drivers\Abstract\Decoders\AbstractDecoder;
|
||||||
|
use Intervention\Image\Exceptions\DecoderException;
|
||||||
use Intervention\Image\Interfaces\ColorInterface;
|
use Intervention\Image\Interfaces\ColorInterface;
|
||||||
use Intervention\Image\Interfaces\DecoderInterface;
|
use Intervention\Image\Interfaces\DecoderInterface;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
@@ -12,7 +13,7 @@ class ImageObjectDecoder extends AbstractDecoder implements DecoderInterface
|
|||||||
public function decode($input): ImageInterface|ColorInterface
|
public function decode($input): ImageInterface|ColorInterface
|
||||||
{
|
{
|
||||||
if (! is_a($input, ImageInterface::class)) {
|
if (! is_a($input, ImageInterface::class)) {
|
||||||
$this->fail();
|
throw new DecoderException('Unable to decode input');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $input;
|
return $input;
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Intervention\Image\Drivers\Gd\Decoders;
|
namespace Intervention\Image\Drivers\Gd\Decoders;
|
||||||
|
|
||||||
|
use Intervention\Image\Exceptions\DecoderException;
|
||||||
use Intervention\Image\Interfaces\ColorInterface;
|
use Intervention\Image\Interfaces\ColorInterface;
|
||||||
use Intervention\Image\Interfaces\DecoderInterface;
|
use Intervention\Image\Interfaces\DecoderInterface;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
@@ -11,11 +12,11 @@ class RgbStringColorDecoder extends ArrayColorDecoder implements DecoderInterfac
|
|||||||
public function decode($input): ImageInterface|ColorInterface
|
public function decode($input): ImageInterface|ColorInterface
|
||||||
{
|
{
|
||||||
if (!is_string($input)) {
|
if (!is_string($input)) {
|
||||||
$this->fail();
|
throw new DecoderException('Unable to decode input');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (substr($input, 0, 3) !== 'rgb') {
|
if (substr($input, 0, 3) !== 'rgb') {
|
||||||
$this->fail();
|
throw new DecoderException('Unable to decode input');
|
||||||
}
|
}
|
||||||
|
|
||||||
// rgb string like rgb(102, 200, 0)
|
// rgb string like rgb(102, 200, 0)
|
||||||
@@ -30,6 +31,6 @@ class RgbStringColorDecoder extends ArrayColorDecoder implements DecoderInterfac
|
|||||||
return parent::decode([$matches['r'], $matches['g'], $matches['b'], $matches['a']]);
|
return parent::decode([$matches['r'], $matches['g'], $matches['b'], $matches['a']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->fail();
|
throw new DecoderException('Unable to decode input');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,18 +2,17 @@
|
|||||||
|
|
||||||
namespace Intervention\Image\Drivers\Gd\Decoders;
|
namespace Intervention\Image\Drivers\Gd\Decoders;
|
||||||
|
|
||||||
use Intervention\Image\Drivers\Gd\Color;
|
use Intervention\Image\Exceptions\DecoderException;
|
||||||
use Intervention\Image\Interfaces\ColorInterface;
|
use Intervention\Image\Interfaces\ColorInterface;
|
||||||
use Intervention\Image\Interfaces\DecoderInterface;
|
use Intervention\Image\Interfaces\DecoderInterface;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
use Intervention\Image\Traits\CanValidateColors;
|
|
||||||
|
|
||||||
class TransparentColorDecoder extends ArrayColorDecoder implements DecoderInterface
|
class TransparentColorDecoder extends ArrayColorDecoder implements DecoderInterface
|
||||||
{
|
{
|
||||||
public function decode($input): ImageInterface|ColorInterface
|
public function decode($input): ImageInterface|ColorInterface
|
||||||
{
|
{
|
||||||
if (! is_string($input) || strtolower($input) !== 'transparent') {
|
if (! is_string($input) || strtolower($input) !== 'transparent') {
|
||||||
$this->fail();
|
throw new DecoderException('Unable to decode input');
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::decode([0, 0, 0, 0]);
|
return parent::decode([0, 0, 0, 0]);
|
||||||
|
@@ -5,6 +5,7 @@ namespace Intervention\Image\Drivers\Imagick\Decoders;
|
|||||||
use ImagickPixel;
|
use ImagickPixel;
|
||||||
use Intervention\Image\Drivers\Abstract\Decoders\AbstractDecoder;
|
use Intervention\Image\Drivers\Abstract\Decoders\AbstractDecoder;
|
||||||
use Intervention\Image\Drivers\Imagick\Color;
|
use Intervention\Image\Drivers\Imagick\Color;
|
||||||
|
use Intervention\Image\Exceptions\DecoderException;
|
||||||
use Intervention\Image\Interfaces\ColorInterface;
|
use Intervention\Image\Interfaces\ColorInterface;
|
||||||
use Intervention\Image\Interfaces\DecoderInterface;
|
use Intervention\Image\Interfaces\DecoderInterface;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
@@ -17,7 +18,7 @@ class ArrayColorDecoder extends AbstractDecoder implements DecoderInterface
|
|||||||
public function decode($input): ImageInterface|ColorInterface
|
public function decode($input): ImageInterface|ColorInterface
|
||||||
{
|
{
|
||||||
if (! $this->isValidColorArray($input)) {
|
if (! $this->isValidColorArray($input)) {
|
||||||
$this->fail();
|
throw new DecoderException('Unable to decode input');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count($input) === 3) {
|
if (count($input) === 3) {
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Intervention\Image\Drivers\Imagick\Decoders;
|
namespace Intervention\Image\Drivers\Imagick\Decoders;
|
||||||
|
|
||||||
|
use Intervention\Image\Exceptions\DecoderException;
|
||||||
use Intervention\Image\Interfaces\ColorInterface;
|
use Intervention\Image\Interfaces\ColorInterface;
|
||||||
use Intervention\Image\Interfaces\DecoderInterface;
|
use Intervention\Image\Interfaces\DecoderInterface;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
@@ -14,7 +15,7 @@ class Base64ImageDecoder extends BinaryImageDecoder implements DecoderInterface
|
|||||||
public function decode($input): ImageInterface|ColorInterface
|
public function decode($input): ImageInterface|ColorInterface
|
||||||
{
|
{
|
||||||
if (! $this->isValidBase64($input)) {
|
if (! $this->isValidBase64($input)) {
|
||||||
$this->fail();
|
throw new DecoderException('Unable to decode input');
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::decode(base64_decode($input));
|
return parent::decode(base64_decode($input));
|
||||||
|
@@ -7,6 +7,7 @@ use Intervention\Image\Collection;
|
|||||||
use Intervention\Image\Drivers\Abstract\Decoders\AbstractDecoder;
|
use Intervention\Image\Drivers\Abstract\Decoders\AbstractDecoder;
|
||||||
use Intervention\Image\Drivers\Imagick\Frame;
|
use Intervention\Image\Drivers\Imagick\Frame;
|
||||||
use Intervention\Image\Drivers\Imagick\Image;
|
use Intervention\Image\Drivers\Imagick\Image;
|
||||||
|
use Intervention\Image\Exceptions\DecoderException;
|
||||||
use Intervention\Image\Interfaces\ColorInterface;
|
use Intervention\Image\Interfaces\ColorInterface;
|
||||||
use Intervention\Image\Interfaces\DecoderInterface;
|
use Intervention\Image\Interfaces\DecoderInterface;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
@@ -16,11 +17,11 @@ class BinaryImageDecoder extends AbstractDecoder implements DecoderInterface
|
|||||||
public function decode($input): ImageInterface|ColorInterface
|
public function decode($input): ImageInterface|ColorInterface
|
||||||
{
|
{
|
||||||
if (!is_string($input)) {
|
if (!is_string($input)) {
|
||||||
$this->fail();
|
throw new DecoderException('Unable to decode input');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $this->inputType($input)->isBinary()) {
|
if (!$this->inputType($input)->isBinary()) {
|
||||||
$this->fail();
|
throw new DecoderException('Unable to decode input');
|
||||||
}
|
}
|
||||||
|
|
||||||
$imagick = new Imagick();
|
$imagick = new Imagick();
|
||||||
|
@@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
namespace Intervention\Image\Drivers\Imagick\Decoders;
|
namespace Intervention\Image\Drivers\Imagick\Decoders;
|
||||||
|
|
||||||
|
use Intervention\Image\Exceptions\DecoderException;
|
||||||
use Intervention\Image\Interfaces\ColorInterface;
|
use Intervention\Image\Interfaces\ColorInterface;
|
||||||
use Intervention\Image\Interfaces\DecoderInterface;
|
use Intervention\Image\Interfaces\DecoderInterface;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
use Intervention\Image\Traits\CanDecodeDataUri;
|
use Intervention\Image\Traits\CanDecodeDataUri;
|
||||||
use Intervention\MimeSniffer\MimeSniffer;
|
|
||||||
|
|
||||||
class DataUriImageDecoder extends BinaryImageDecoder implements DecoderInterface
|
class DataUriImageDecoder extends BinaryImageDecoder implements DecoderInterface
|
||||||
{
|
{
|
||||||
@@ -15,13 +15,13 @@ class DataUriImageDecoder extends BinaryImageDecoder implements DecoderInterface
|
|||||||
public function decode($input): ImageInterface|ColorInterface
|
public function decode($input): ImageInterface|ColorInterface
|
||||||
{
|
{
|
||||||
if (!is_string($input)) {
|
if (!is_string($input)) {
|
||||||
$this->fail();
|
throw new DecoderException('Unable to decode input');
|
||||||
}
|
}
|
||||||
|
|
||||||
$uri = $this->decodeDataUri($input);
|
$uri = $this->decodeDataUri($input);
|
||||||
|
|
||||||
if (! $uri->isValid()) {
|
if (! $uri->isValid()) {
|
||||||
$this->fail();
|
throw new DecoderException('Unable to decode input');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($uri->isBase64Encoded()) {
|
if ($uri->isBase64Encoded()) {
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
namespace Intervention\Image\Drivers\Imagick\Decoders;
|
namespace Intervention\Image\Drivers\Imagick\Decoders;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use Intervention\Image\Exceptions\DecoderException;
|
||||||
use Intervention\Image\Interfaces\ColorInterface;
|
use Intervention\Image\Interfaces\ColorInterface;
|
||||||
use Intervention\Image\Interfaces\DecoderInterface;
|
use Intervention\Image\Interfaces\DecoderInterface;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
@@ -12,15 +13,15 @@ class FilePathImageDecoder extends BinaryImageDecoder implements DecoderInterfac
|
|||||||
public function decode($input): ImageInterface|ColorInterface
|
public function decode($input): ImageInterface|ColorInterface
|
||||||
{
|
{
|
||||||
if (! is_string($input)) {
|
if (! is_string($input)) {
|
||||||
$this->fail();
|
throw new DecoderException('Unable to decode input');
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (! @is_file($input)) {
|
if (! @is_file($input)) {
|
||||||
$this->fail();
|
throw new DecoderException('Unable to decode input');
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$this->fail();
|
throw new DecoderException('Unable to decode input');
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::decode(file_get_contents($input));
|
return parent::decode(file_get_contents($input));
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Intervention\Image\Drivers\Imagick\Decoders;
|
namespace Intervention\Image\Drivers\Imagick\Decoders;
|
||||||
|
|
||||||
use Intervention\Image\Drivers\Imagick\Color;
|
use Intervention\Image\Exceptions\DecoderException;
|
||||||
use Intervention\Image\Interfaces\ColorInterface;
|
use Intervention\Image\Interfaces\ColorInterface;
|
||||||
use Intervention\Image\Interfaces\DecoderInterface;
|
use Intervention\Image\Interfaces\DecoderInterface;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
@@ -12,14 +12,14 @@ class HexColorDecoder extends ArrayColorDecoder implements DecoderInterface
|
|||||||
public function decode($input): ImageInterface|ColorInterface
|
public function decode($input): ImageInterface|ColorInterface
|
||||||
{
|
{
|
||||||
if (!is_string($input)) {
|
if (!is_string($input)) {
|
||||||
$this->fail();
|
throw new DecoderException('Unable to decode input');
|
||||||
}
|
}
|
||||||
|
|
||||||
$pattern = '/^#?([a-f0-9]{1,2})([a-f0-9]{1,2})([a-f0-9]{1,2})$/i';
|
$pattern = '/^#?([a-f0-9]{1,2})([a-f0-9]{1,2})([a-f0-9]{1,2})$/i';
|
||||||
$result = preg_match($pattern, $input, $matches);
|
$result = preg_match($pattern, $input, $matches);
|
||||||
|
|
||||||
if ($result !== 1) {
|
if ($result !== 1) {
|
||||||
$this->fail();
|
throw new DecoderException('Unable to decode input');
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::decode([
|
return parent::decode([
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
namespace Intervention\Image\Drivers\Imagick\Decoders;
|
namespace Intervention\Image\Drivers\Imagick\Decoders;
|
||||||
|
|
||||||
use Intervention\Image\Drivers\Abstract\Decoders\AbstractDecoder;
|
use Intervention\Image\Drivers\Abstract\Decoders\AbstractDecoder;
|
||||||
|
use Intervention\Image\Exceptions\DecoderException;
|
||||||
use Intervention\Image\Interfaces\ColorInterface;
|
use Intervention\Image\Interfaces\ColorInterface;
|
||||||
use Intervention\Image\Interfaces\DecoderInterface;
|
use Intervention\Image\Interfaces\DecoderInterface;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
@@ -12,7 +13,7 @@ class ImageObjectDecoder extends AbstractDecoder implements DecoderInterface
|
|||||||
public function decode($input): ImageInterface|ColorInterface
|
public function decode($input): ImageInterface|ColorInterface
|
||||||
{
|
{
|
||||||
if (! is_a($input, ImageInterface::class)) {
|
if (! is_a($input, ImageInterface::class)) {
|
||||||
$this->fail();
|
throw new DecoderException('Unable to decode input');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $input;
|
return $input;
|
||||||
|
@@ -6,27 +6,27 @@ use ImagickPixel;
|
|||||||
use ImagickPixelException;
|
use ImagickPixelException;
|
||||||
use Intervention\Image\Drivers\Abstract\Decoders\AbstractDecoder;
|
use Intervention\Image\Drivers\Abstract\Decoders\AbstractDecoder;
|
||||||
use Intervention\Image\Drivers\Imagick\Color;
|
use Intervention\Image\Drivers\Imagick\Color;
|
||||||
|
use Intervention\Image\Exceptions\DecoderException;
|
||||||
use Intervention\Image\Interfaces\ColorInterface;
|
use Intervention\Image\Interfaces\ColorInterface;
|
||||||
use Intervention\Image\Interfaces\DecoderInterface;
|
use Intervention\Image\Interfaces\DecoderInterface;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
use Intervention\Image\Traits\CanValidateColors;
|
|
||||||
|
|
||||||
class RgbStringColorDecoder extends AbstractDecoder implements DecoderInterface
|
class RgbStringColorDecoder extends AbstractDecoder implements DecoderInterface
|
||||||
{
|
{
|
||||||
public function decode($input): ImageInterface|ColorInterface
|
public function decode($input): ImageInterface|ColorInterface
|
||||||
{
|
{
|
||||||
if (!is_string($input)) {
|
if (!is_string($input)) {
|
||||||
$this->fail();
|
throw new DecoderException('Unable to decode input');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (substr($input, 0, 3) !== 'rgb') {
|
if (substr($input, 0, 3) !== 'rgb') {
|
||||||
$this->fail();
|
throw new DecoderException('Unable to decode input');
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$pixel = new ImagickPixel($input);
|
$pixel = new ImagickPixel($input);
|
||||||
} catch (ImagickPixelException $e) {
|
} catch (ImagickPixelException $e) {
|
||||||
$this->fail();
|
throw new DecoderException('Unable to decode input');
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Color($pixel);
|
return new Color($pixel);
|
||||||
|
@@ -2,18 +2,17 @@
|
|||||||
|
|
||||||
namespace Intervention\Image\Drivers\Imagick\Decoders;
|
namespace Intervention\Image\Drivers\Imagick\Decoders;
|
||||||
|
|
||||||
use Intervention\Image\Drivers\Imagick\Color;
|
use Intervention\Image\Exceptions\DecoderException;
|
||||||
use Intervention\Image\Interfaces\ColorInterface;
|
use Intervention\Image\Interfaces\ColorInterface;
|
||||||
use Intervention\Image\Interfaces\DecoderInterface;
|
use Intervention\Image\Interfaces\DecoderInterface;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
use Intervention\Image\Traits\CanValidateColors;
|
|
||||||
|
|
||||||
class TransparentColorDecoder extends ArrayColorDecoder implements DecoderInterface
|
class TransparentColorDecoder extends ArrayColorDecoder implements DecoderInterface
|
||||||
{
|
{
|
||||||
public function decode($input): ImageInterface|ColorInterface
|
public function decode($input): ImageInterface|ColorInterface
|
||||||
{
|
{
|
||||||
if (! is_string($input) || strtolower($input) !== 'transparent') {
|
if (! is_string($input) || strtolower($input) !== 'transparent') {
|
||||||
$this->fail();
|
throw new DecoderException('Unable to decode input');
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::decode([0, 0, 0, 0]);
|
return parent::decode([0, 0, 0, 0]);
|
||||||
|
Reference in New Issue
Block a user