mirror of
https://github.com/Intervention/image.git
synced 2025-08-31 01:29:51 +02:00
different solution, prefer extension over imagick
This commit is contained in:
@@ -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();
|
||||
|
@@ -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'
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@@ -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()
|
||||
|
Reference in New Issue
Block a user