1
0
mirror of https://github.com/Intervention/image.git synced 2025-09-02 10:23:29 +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:
Simon Gow
2019-01-30 17:28:28 +13:00
parent e82d274f78
commit bcf9679a73

View File

@@ -2,6 +2,8 @@
namespace Intervention\Image\Commands;
use Intervention\Image\Exception\NotReadableException;
class ExifCommand extends AbstractCommand
{
/**
@@ -15,7 +17,7 @@ class ExifCommand extends AbstractCommand
*/
public function execute($image)
{
if ( ! function_exists('exif_read_data')) {
if (!function_exists('exif_read_data')) {
throw new \Intervention\Image\Exception\NotSupportedException(
"Reading Exif data is not supported by this PHP installation."
);
@@ -24,14 +26,25 @@ class ExifCommand extends AbstractCommand
$key = $this->argument(0)->value();
// 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)) {
$data = array_key_exists($key, $data) ? $data[$key] : false;
if (!is_null($key) && is_array($data)) {
$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);
return true;
}
}