mirror of
https://github.com/Intervention/image.git
synced 2025-08-01 03:20:17 +02:00
Optimize code
This commit is contained in:
@@ -26,10 +26,6 @@ abstract class AbstractDecoder extends SpecializableDecoder implements Specializ
|
|||||||
throw new DecoderException('Unable to detect media (MIME) from data in file path.');
|
throw new DecoderException('Unable to detect media (MIME) from data in file path.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!array_key_exists('mime', $info)) {
|
|
||||||
throw new DecoderException('Unable to detect media (MIME) from data in file path.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return MediaType::from($info['mime']);
|
return MediaType::from($info['mime']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,10 +44,6 @@ abstract class AbstractDecoder extends SpecializableDecoder implements Specializ
|
|||||||
throw new DecoderException('Unable to detect media (MIME) from binary data.');
|
throw new DecoderException('Unable to detect media (MIME) from binary data.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!array_key_exists('mime', $info)) {
|
|
||||||
throw new DecoderException('Unable to detect media (MIME) from binary data.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return MediaType::from($info['mime']);
|
return MediaType::from($info['mime']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -6,6 +6,7 @@ namespace Intervention\Image\Drivers\Gd;
|
|||||||
|
|
||||||
use GdImage;
|
use GdImage;
|
||||||
use Intervention\Image\Exceptions\ColorException;
|
use Intervention\Image\Exceptions\ColorException;
|
||||||
|
use Intervention\Image\Exceptions\InputException;
|
||||||
use Intervention\Image\Geometry\Rectangle;
|
use Intervention\Image\Geometry\Rectangle;
|
||||||
use Intervention\Image\Image;
|
use Intervention\Image\Image;
|
||||||
use Intervention\Image\Interfaces\DriverInterface;
|
use Intervention\Image\Interfaces\DriverInterface;
|
||||||
@@ -112,9 +113,14 @@ class Frame implements FrameInterface
|
|||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*
|
*
|
||||||
* @see FrameInterface::setDispose()
|
* @see FrameInterface::setDispose()
|
||||||
|
* @throws InputException
|
||||||
*/
|
*/
|
||||||
public function setDispose(int $dispose): FrameInterface
|
public function setDispose(int $dispose): FrameInterface
|
||||||
{
|
{
|
||||||
|
if (!in_array($dispose, [0, 1, 2, 3])) {
|
||||||
|
throw new InputException('Value for argument $dispose must be 0, 1, 2 or 3.');
|
||||||
|
}
|
||||||
|
|
||||||
$this->dispose = $dispose;
|
$this->dispose = $dispose;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
@@ -7,6 +7,7 @@ namespace Intervention\Image\Drivers\Imagick;
|
|||||||
use Imagick;
|
use Imagick;
|
||||||
use ImagickException;
|
use ImagickException;
|
||||||
use ImagickPixel;
|
use ImagickPixel;
|
||||||
|
use Intervention\Image\Exceptions\InputException;
|
||||||
use Intervention\Image\Geometry\Rectangle;
|
use Intervention\Image\Geometry\Rectangle;
|
||||||
use Intervention\Image\Image;
|
use Intervention\Image\Image;
|
||||||
use Intervention\Image\Interfaces\DriverInterface;
|
use Intervention\Image\Interfaces\DriverInterface;
|
||||||
@@ -111,9 +112,14 @@ class Frame implements FrameInterface
|
|||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*
|
*
|
||||||
* @see DriverInterface::setDispose()
|
* @see DriverInterface::setDispose()
|
||||||
|
* @throws InputException
|
||||||
*/
|
*/
|
||||||
public function setDispose(int $dispose): FrameInterface
|
public function setDispose(int $dispose): FrameInterface
|
||||||
{
|
{
|
||||||
|
if (!in_array($dispose, [0, 1, 2, 3])) {
|
||||||
|
throw new InputException('Value for argument $dispose must be 0, 1, 2 or 3.');
|
||||||
|
}
|
||||||
|
|
||||||
$this->native->setImageDispose($dispose);
|
$this->native->setImageDispose($dispose);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
@@ -66,9 +66,9 @@ final class FrameTest extends BaseTestCase
|
|||||||
$frame = $this->getTestFrame();
|
$frame = $this->getTestFrame();
|
||||||
$this->assertEquals(1, $frame->dispose());
|
$this->assertEquals(1, $frame->dispose());
|
||||||
|
|
||||||
$result = $frame->setDispose(100);
|
$result = $frame->setDispose(3);
|
||||||
$this->assertInstanceOf(Frame::class, $result);
|
$this->assertInstanceOf(Frame::class, $result);
|
||||||
$this->assertEquals(100, $frame->dispose());
|
$this->assertEquals(3, $frame->dispose());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetGetOffsetLeft(): void
|
public function testSetGetOffsetLeft(): void
|
||||||
|
@@ -23,7 +23,7 @@ final class FrameTest extends BaseTestCase
|
|||||||
$imagick = new Imagick();
|
$imagick = new Imagick();
|
||||||
$imagick->newImage(3, 2, new ImagickPixel('red'), 'png');
|
$imagick->newImage(3, 2, new ImagickPixel('red'), 'png');
|
||||||
$imagick->setImageDelay(125); // 1.25 seconds
|
$imagick->setImageDelay(125); // 1.25 seconds
|
||||||
$imagick->setImageDispose(5);
|
$imagick->setImageDispose(0);
|
||||||
$imagick->setImagePage(3, 2, 8, 9);
|
$imagick->setImagePage(3, 2, 8, 9);
|
||||||
|
|
||||||
return new Frame($imagick);
|
return new Frame($imagick);
|
||||||
@@ -55,11 +55,11 @@ final class FrameTest extends BaseTestCase
|
|||||||
public function testSetGetDispose(): void
|
public function testSetGetDispose(): void
|
||||||
{
|
{
|
||||||
$frame = $this->getTestFrame();
|
$frame = $this->getTestFrame();
|
||||||
$this->assertEquals(5, $frame->dispose());
|
$this->assertEquals(0, $frame->dispose());
|
||||||
|
|
||||||
$result = $frame->setDispose(100);
|
$result = $frame->setDispose(3);
|
||||||
$this->assertInstanceOf(Frame::class, $result);
|
$this->assertInstanceOf(Frame::class, $result);
|
||||||
$this->assertEquals(100, $frame->dispose());
|
$this->assertEquals(3, $frame->dispose());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetGetOffsetLeft(): void
|
public function testSetGetOffsetLeft(): void
|
||||||
|
Reference in New Issue
Block a user