quickwebp
/
includes
/
vendor
/
intervention
/
image
/
src
/
Intervention
/
Image
/
Commands
/
ExifCommand.php
ExifCommand.php in QuickWebP – WebP & AVIF Image Optimizer, Compression & SEO for WordPress 3.2.1, at includes/vendor/intervention/image/src/Intervention/Image/Commands/ExifCommand.php
| 1 | <?php |
| 2 | |
| 3 | namespace Intervention\Image\Commands; |
| 4 | |
| 5 | use Intervention\Image\Exception\NotReadableException; |
| 6 | use Intervention\Image\Exception\NotSupportedException; |
| 7 | |
| 8 | class ExifCommand extends AbstractCommand |
| 9 | { |
| 10 | /** |
| 11 | * Read Exif data from the given image |
| 12 | * |
| 13 | * Note: Windows PHP Users - in order to use this method you will need to |
| 14 | * enable the mbstring and exif extensions within the php.ini file. |
| 15 | * |
| 16 | * @param \Intervention\Image\Image $image |
| 17 | * @return boolean |
| 18 | */ |
| 19 | public function execute($image) |
| 20 | { |
| 21 | if (!function_exists('exif_read_data')) { |
| 22 | throw new NotSupportedException( |
| 23 | "Reading Exif data is not supported by this PHP installation." |
| 24 | ); |
| 25 | } |
| 26 | |
| 27 | $key = $this->argument(0)->value(); |
| 28 | |
| 29 | // try to read exif data from image file |
| 30 | try { |
| 31 | if ($image->dirname && $image->basename) { |
| 32 | $stream = $image->dirname . '/' . $image->basename; |
| 33 | } elseif (version_compare(PHP_VERSION, '7.2.0', '>=')) { |
| 34 | // https://www.php.net/manual/en/function.exif-read-data.php#refsect1-function.exif-read-data-changelog |
| 35 | $stream = $image->stream()->detach(); |
| 36 | } else { |
| 37 | // https://bugs.php.net/bug.php?id=65187 |
| 38 | $stream = $image->encode('data-url')->encoded; |
| 39 | } |
| 40 | |
| 41 | $data = @exif_read_data($stream); |
| 42 | |
| 43 | if (!is_null($key) && is_array($data)) { |
| 44 | $data = array_key_exists($key, $data) ? $data[$key] : false; |
| 45 | } |
| 46 | |
| 47 | } catch (\Exception $e) { |
| 48 | throw new NotReadableException( |
| 49 | sprintf( |
| 50 | "Cannot read the Exif data from the filename (%s) provided ", |
| 51 | $image->dirname . '/' . $image->basename |
| 52 | ), |
| 53 | $e->getCode(), |
| 54 | $e |
| 55 | ); |
| 56 | } |
| 57 | |
| 58 | $this->setOutput($data); |
| 59 | return true; |
| 60 | } |
| 61 | } |
| 62 |