mirror of
https://github.com/Intervention/image.git
synced 2025-08-17 11:20:44 +02:00
fixed bug when trying to read non-existent exif data
This commit is contained in:
@@ -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;
|
||||
|
@@ -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());
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user