From 246341693db72460d9fb0d6d29dd142c8bd1136d Mon Sep 17 00:00:00 2001 From: Frederik Bosch Date: Sat, 7 Jan 2017 18:12:53 +0100 Subject: [PATCH] different solution, prefer extension over imagick --- .../Image/Imagick/Commands/ExifCommand.php | 23 +++++++++++-- tests/ExifCommandTest.php | 32 +++++++++---------- tests/ImagickSystemTest.php | 2 +- 3 files changed, 37 insertions(+), 20 deletions(-) diff --git a/src/Intervention/Image/Imagick/Commands/ExifCommand.php b/src/Intervention/Image/Imagick/Commands/ExifCommand.php index 31209e4d..3d54fedc 100644 --- a/src/Intervention/Image/Imagick/Commands/ExifCommand.php +++ b/src/Intervention/Image/Imagick/Commands/ExifCommand.php @@ -6,6 +6,20 @@ use Intervention\Image\Commands\ExifCommand as BaseCommand; class ExifCommand extends BaseCommand { + /** + * Prefer extension or not + * + * @var bool + */ + private $preferExtension = true; + + /** + * + */ + public function dontPreferExtension() { + $this->preferExtension = false; + } + /** * Read Exif data from the given image * @@ -14,11 +28,16 @@ class ExifCommand extends BaseCommand */ public function execute($image) { + if ($this->preferExtension && function_exists('exif_read_data')) { + return parent::execute($image); + } + $core = $image->getCore(); - // when getImageProperty is not supported fallback to default exif command if ( ! method_exists($core, 'getImageProperties')) { - return parent::execute($image); + throw new \Intervention\Image\Exception\NotSupportedException( + "Reading Exif data is not supported by this PHP installation." + ); } $requestedKey = $this->argument(0)->value(); diff --git a/tests/ExifCommandTest.php b/tests/ExifCommandTest.php index 0fa60489..074ed664 100644 --- a/tests/ExifCommandTest.php +++ b/tests/ExifCommandTest.php @@ -60,23 +60,20 @@ class ExifCommandTest extends PHPUnit_Framework_TestCase public function testImagickFetchAll() { - $image = new Image; - $image->dirname = __DIR__.'/images'; - $image->basename = 'exif.jpg'; + $image = $this->imagick()->make(__DIR__.'/images/exif.jpg'); $command = new \Intervention\Image\Imagick\Commands\ExifCommand(array()); + $command->dontPreferExtension(); $result = $command->execute($image); $this->assertTrue($result); $this->assertTrue($command->hasOutput()); $this->assertInternalType('array', $command->getOutput()); - $this->assertCount(19, $command->getOutput()); } public function testImagickFetchDefined() { - $image = new Image; - $image->dirname = __DIR__.'/images'; - $image->basename = 'exif.jpg'; + $image = $this->imagick()->make(__DIR__.'/images/exif.jpg'); $command = new \Intervention\Image\Imagick\Commands\ExifCommand(array('Artist')); + $command->dontPreferExtension(); $result = $command->execute($image); $this->assertTrue($result); $this->assertTrue($command->hasOutput()); @@ -85,10 +82,9 @@ class ExifCommandTest extends PHPUnit_Framework_TestCase public function testImagickNonExisting() { - $image = new Image; - $image->dirname = __DIR__.'/images'; - $image->basename = 'exif.jpg'; - $command = new \Intervention\Image\Imagick\Commands\ExifCommand(array('xxx')); + $image = $this->imagick()->make(__DIR__.'/images/exif.jpg'); + $command = new \Intervention\Image\Imagick\Commands\ExifCommand(array('xx')); + $command->dontPreferExtension(); $result = $command->execute($image); $this->assertTrue($result); $this->assertTrue($command->hasOutput()); @@ -97,16 +93,18 @@ class ExifCommandTest extends PHPUnit_Framework_TestCase public function testImagickFallbackToExifExtenstion() { - $imagick = Mockery::mock('stdClass'); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($imagick); - $image->dirname = __DIR__.'/images'; - $image->basename = 'exif.jpg'; - + $image = $this->imagick()->make(__DIR__.'/images/exif.jpg'); $command = new \Intervention\Image\Imagick\Commands\ExifCommand(array('Artist')); $result = $command->execute($image); $this->assertTrue($result); $this->assertTrue($command->hasOutput()); $this->assertEquals('Oliver Vogel', $command->getOutput()); } + + private function imagick() + { + return new \Intervention\Image\ImageManager(array( + 'driver' => 'imagick' + )); + } } diff --git a/tests/ImagickSystemTest.php b/tests/ImagickSystemTest.php index 89b8f8ee..7c4419ac 100644 --- a/tests/ImagickSystemTest.php +++ b/tests/ImagickSystemTest.php @@ -1465,7 +1465,7 @@ class ImagickSystemTest extends PHPUnit_Framework_TestCase $img = $this->manager()->make('tests/images/exif.jpg'); $data = $img->exif(); $this->assertInternalType('array', $data); - $this->assertEquals(19, count($data)); + $this->assertGreaterThanOrEqual(13, count($data)); } public function testExifReadKey()