mirror of
https://github.com/Intervention/image.git
synced 2025-09-03 10:53:01 +02:00
Throw NotReadable exception if the exif_read_data fails
PNGs and corrupted images will raise exceptions and need to be hanlded correctly. Stop handling and raise an appropriate exception.
This commit is contained in:
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace Intervention\Image\Commands;
|
namespace Intervention\Image\Commands;
|
||||||
|
|
||||||
|
use Intervention\Image\Exception\NotReadableException;
|
||||||
|
|
||||||
class ExifCommand extends AbstractCommand
|
class ExifCommand extends AbstractCommand
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@@ -15,7 +17,7 @@ class ExifCommand extends AbstractCommand
|
|||||||
*/
|
*/
|
||||||
public function execute($image)
|
public function execute($image)
|
||||||
{
|
{
|
||||||
if ( ! function_exists('exif_read_data')) {
|
if (!function_exists('exif_read_data')) {
|
||||||
throw new \Intervention\Image\Exception\NotSupportedException(
|
throw new \Intervention\Image\Exception\NotSupportedException(
|
||||||
"Reading Exif data is not supported by this PHP installation."
|
"Reading Exif data is not supported by this PHP installation."
|
||||||
);
|
);
|
||||||
@@ -24,14 +26,25 @@ class ExifCommand extends AbstractCommand
|
|||||||
$key = $this->argument(0)->value();
|
$key = $this->argument(0)->value();
|
||||||
|
|
||||||
// try to read exif data from image file
|
// try to read exif data from image file
|
||||||
$data = @exif_read_data($image->dirname .'/'. $image->basename);
|
try {
|
||||||
|
$data = @exif_read_data($image->dirname . '/' . $image->basename);
|
||||||
|
|
||||||
if (! is_null($key) && is_array($data)) {
|
if (!is_null($key) && is_array($data)) {
|
||||||
$data = array_key_exists($key, $data) ? $data[$key] : false;
|
$data = array_key_exists($key, $data) ? $data[$key] : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
throw new NotReadableException(
|
||||||
|
sprintf(
|
||||||
|
"Cannot read the Exif data from the filename (%s) provided ",
|
||||||
|
$image->dirname . '/' . $image->basename
|
||||||
|
),
|
||||||
|
$e->getCode(),
|
||||||
|
$e
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setOutput($data);
|
$this->setOutput($data);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user