1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-16 19:04:00 +02:00

fixed bug when trying to read non-existent exif data

This commit is contained in:
Oliver Vogel
2014-06-07 19:56:51 +02:00
parent d6f89cc9bf
commit a17342106a
3 changed files with 34 additions and 1 deletions

View File

@@ -22,7 +22,9 @@ class ExifCommand extends AbstractCommand
}
$key = $this->argument(0)->value();
$data = exif_read_data($image->dirname .'/'. $image->basename, 'EXIF', false);
// try to read exif data from image file
$data = @exif_read_data($image->dirname .'/'. $image->basename, 'EXIF', false);
if (! is_null($key) && is_array($data)) {
$data = array_key_exists($key, $data) ? $data[$key] : false;

View File

@@ -44,4 +44,26 @@ class ExifCommandTest extends PHPUnit_Framework_TestCase
$this->assertTrue($command->hasOutput());
$this->assertEquals(null, $command->getOutput());
}
public function testFetchFromPng()
{
$image = Mockery::mock('Intervention\Image\Image');
$image->dirname = __DIR__.'/images';
$image->basename = 'star.png';
$command = new ExifCommand(array('Orientation'));
$result = $command->execute($image);
$this->assertTrue($result);
$this->assertTrue($command->hasOutput());
$this->assertEquals(null, $command->getOutput());
}
public function testReturnNullOnExifReadFail()
{
$image = Mockery::mock('Intervention\Image\Image');
$command = new ExifCommand(array('Orientation'));
$result = $command->execute($image);
$this->assertTrue($result);
$this->assertTrue($command->hasOutput());
$this->assertEquals(null, $command->getOutput());
}
}

View File

@@ -81,4 +81,13 @@ class OrientateCommandTest extends PHPUnit_Framework_TestCase
$result = $command->execute($image);
$this->assertTrue($result);
}
public function testExecuteOrientationNoExifData()
{
$image = Mockery::mock('Intervention\Image\Image');
$image->shouldReceive('exif')->with('Orientation')->once()->andReturn(null);
$command = new OrientateCommand(array());
$result = $command->execute($image);
$this->assertTrue($result);
}
}