diff --git a/src/Intervention/Image/AbstractDecoder.php b/src/Intervention/Image/AbstractDecoder.php index 5eabd8ff..ead7c48d 100644 --- a/src/Intervention/Image/AbstractDecoder.php +++ b/src/Intervention/Image/AbstractDecoder.php @@ -216,6 +216,10 @@ abstract class AbstractDecoder */ public function isBase64() { + if (!is_string($this->data)) { + return false; + } + return base64_encode(base64_decode($this->data)) === $this->data; } @@ -238,6 +242,10 @@ abstract class AbstractDecoder */ private function decodeDataUrl($data_url) { + if (!is_string($data_url)) { + return null; + } + $pattern = "/^data:(?:image\/[a-zA-Z\-\.]+)(?:charset=\".+\")?;base64,(?P.+)$/"; preg_match($pattern, $data_url, $matches); diff --git a/tests/FillCommandTest.php b/tests/FillCommandTest.php index 6a851fc2..b4d92c9f 100644 --- a/tests/FillCommandTest.php +++ b/tests/FillCommandTest.php @@ -22,6 +22,30 @@ class FillCommandTest extends PHPUnit_Framework_TestCase $this->assertTrue($result); } + public function testGdFillArray() + { + $resource = imagecreatefromjpeg(__DIR__.'/images/test.jpg'); + $image = Mockery::mock('Intervention\Image\Image'); + $image->shouldReceive('getCore')->once()->andReturn($resource); + $image->shouldReceive('getWidth')->once()->andReturn(800); + $image->shouldReceive('getHeight')->once()->andReturn(600); + $command = new FillGd(array(array(50, 50, 50))); + $result = $command->execute($image); + $this->assertTrue($result); + } + + public function testGdFillArrayWithAlpha() + { + $resource = imagecreatefromjpeg(__DIR__.'/images/test.jpg'); + $image = Mockery::mock('Intervention\Image\Image'); + $image->shouldReceive('getCore')->once()->andReturn($resource); + $image->shouldReceive('getWidth')->once()->andReturn(800); + $image->shouldReceive('getHeight')->once()->andReturn(600); + $command = new FillGd(array(array(50, 50, 50, .50))); + $result = $command->execute($image); + $this->assertTrue($result); + } + public function testGdFillWithCoordinates() { $driver = Mockery::mock('\Intervention\Image\Gd\Driver');