Exif.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * @package Grav\Common\Helpers
  4. *
  5. * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
  6. * @license MIT License; see LICENSE file for details.
  7. */
  8. namespace Grav\Common\Helpers;
  9. use Grav\Common\Grav;
  10. use PHPExif\Reader\Reader;
  11. use RuntimeException;
  12. use function function_exists;
  13. /**
  14. * Class Exif
  15. * @package Grav\Common\Helpers
  16. */
  17. class Exif
  18. {
  19. /** @var Reader */
  20. public $reader;
  21. /**
  22. * Exif constructor.
  23. * @throws RuntimeException
  24. */
  25. public function __construct()
  26. {
  27. if (Grav::instance()['config']->get('system.media.auto_metadata_exif')) {
  28. if (function_exists('exif_read_data') && class_exists(Reader::class)) {
  29. $this->reader = Reader::factory(Reader::TYPE_NATIVE);
  30. } else {
  31. throw new RuntimeException('Please enable the Exif extension for PHP or disable Exif support in Grav system configuration');
  32. }
  33. }
  34. }
  35. /**
  36. * @return Reader
  37. */
  38. public function getReader()
  39. {
  40. return $this->reader;
  41. }
  42. }