ExifCommand.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace Intervention\Image\Commands;
  3. class ExifCommand extends AbstractCommand
  4. {
  5. /**
  6. * Read Exif data from the given image
  7. *
  8. * Note: Windows PHP Users - in order to use this method you will need to
  9. * enable the mbstring and exif extensions within the php.ini file.
  10. *
  11. * @param \Intervention\Image\Image $image
  12. * @return boolean
  13. */
  14. public function execute($image)
  15. {
  16. if ( ! function_exists('exif_read_data')) {
  17. throw new \Intervention\Image\Exception\NotSupportedException(
  18. "Reading Exif data is not supported by this PHP installation."
  19. );
  20. }
  21. $key = $this->argument(0)->value();
  22. // try to read exif data from image file
  23. $data = @exif_read_data($image->dirname .'/'. $image->basename);
  24. if (! is_null($key) && is_array($data)) {
  25. $data = array_key_exists($key, $data) ? $data[$key] : false;
  26. }
  27. $this->setOutput($data);
  28. return true;
  29. }
  30. }