1
0
mirror of https://github.com/Intervention/image.git synced 2025-09-02 02:12:37 +02:00

different solution, prefer extension over imagick

This commit is contained in:
Frederik Bosch
2017-01-07 18:12:53 +01:00
parent bd9a631d78
commit 246341693d
3 changed files with 37 additions and 20 deletions

View File

@@ -6,6 +6,20 @@ use Intervention\Image\Commands\ExifCommand as BaseCommand;
class ExifCommand extends 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 * Read Exif data from the given image
* *
@@ -14,11 +28,16 @@ class ExifCommand extends BaseCommand
*/ */
public function execute($image) public function execute($image)
{ {
if ($this->preferExtension && function_exists('exif_read_data')) {
return parent::execute($image);
}
$core = $image->getCore(); $core = $image->getCore();
// when getImageProperty is not supported fallback to default exif command
if ( ! method_exists($core, 'getImageProperties')) { 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(); $requestedKey = $this->argument(0)->value();

View File

@@ -60,23 +60,20 @@ class ExifCommandTest extends PHPUnit_Framework_TestCase
public function testImagickFetchAll() public function testImagickFetchAll()
{ {
$image = new Image; $image = $this->imagick()->make(__DIR__.'/images/exif.jpg');
$image->dirname = __DIR__.'/images';
$image->basename = 'exif.jpg';
$command = new \Intervention\Image\Imagick\Commands\ExifCommand(array()); $command = new \Intervention\Image\Imagick\Commands\ExifCommand(array());
$command->dontPreferExtension();
$result = $command->execute($image); $result = $command->execute($image);
$this->assertTrue($result); $this->assertTrue($result);
$this->assertTrue($command->hasOutput()); $this->assertTrue($command->hasOutput());
$this->assertInternalType('array', $command->getOutput()); $this->assertInternalType('array', $command->getOutput());
$this->assertCount(19, $command->getOutput());
} }
public function testImagickFetchDefined() public function testImagickFetchDefined()
{ {
$image = new Image; $image = $this->imagick()->make(__DIR__.'/images/exif.jpg');
$image->dirname = __DIR__.'/images';
$image->basename = 'exif.jpg';
$command = new \Intervention\Image\Imagick\Commands\ExifCommand(array('Artist')); $command = new \Intervention\Image\Imagick\Commands\ExifCommand(array('Artist'));
$command->dontPreferExtension();
$result = $command->execute($image); $result = $command->execute($image);
$this->assertTrue($result); $this->assertTrue($result);
$this->assertTrue($command->hasOutput()); $this->assertTrue($command->hasOutput());
@@ -85,10 +82,9 @@ class ExifCommandTest extends PHPUnit_Framework_TestCase
public function testImagickNonExisting() public function testImagickNonExisting()
{ {
$image = new Image; $image = $this->imagick()->make(__DIR__.'/images/exif.jpg');
$image->dirname = __DIR__.'/images'; $command = new \Intervention\Image\Imagick\Commands\ExifCommand(array('xx'));
$image->basename = 'exif.jpg'; $command->dontPreferExtension();
$command = new \Intervention\Image\Imagick\Commands\ExifCommand(array('xxx'));
$result = $command->execute($image); $result = $command->execute($image);
$this->assertTrue($result); $this->assertTrue($result);
$this->assertTrue($command->hasOutput()); $this->assertTrue($command->hasOutput());
@@ -97,16 +93,18 @@ class ExifCommandTest extends PHPUnit_Framework_TestCase
public function testImagickFallbackToExifExtenstion() public function testImagickFallbackToExifExtenstion()
{ {
$imagick = Mockery::mock('stdClass'); $image = $this->imagick()->make(__DIR__.'/images/exif.jpg');
$image = Mockery::mock('Intervention\Image\Image');
$image->shouldReceive('getCore')->once()->andReturn($imagick);
$image->dirname = __DIR__.'/images';
$image->basename = 'exif.jpg';
$command = new \Intervention\Image\Imagick\Commands\ExifCommand(array('Artist')); $command = new \Intervention\Image\Imagick\Commands\ExifCommand(array('Artist'));
$result = $command->execute($image); $result = $command->execute($image);
$this->assertTrue($result); $this->assertTrue($result);
$this->assertTrue($command->hasOutput()); $this->assertTrue($command->hasOutput());
$this->assertEquals('Oliver Vogel', $command->getOutput()); $this->assertEquals('Oliver Vogel', $command->getOutput());
} }
private function imagick()
{
return new \Intervention\Image\ImageManager(array(
'driver' => 'imagick'
));
}
} }

View File

@@ -1465,7 +1465,7 @@ class ImagickSystemTest extends PHPUnit_Framework_TestCase
$img = $this->manager()->make('tests/images/exif.jpg'); $img = $this->manager()->make('tests/images/exif.jpg');
$data = $img->exif(); $data = $img->exif();
$this->assertInternalType('array', $data); $this->assertInternalType('array', $data);
$this->assertEquals(19, count($data)); $this->assertGreaterThanOrEqual(13, count($data));
} }
public function testExifReadKey() public function testExifReadKey()