PreviewExtractor.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * This file is part of the PHPExiftool package.
  4. *
  5. * (c) Alchemy <support@alchemy.fr>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace PHPExiftool;
  11. use PHPExiftool\Exception\LogicException;
  12. use PHPExiftool\Exception\RuntimeException;
  13. class PreviewExtractor extends Exiftool
  14. {
  15. private $exiftool;
  16. public function __construct(Exiftool $exiftool)
  17. {
  18. $this->exiftool = $exiftool;
  19. }
  20. public function extract($pathfile, $outputDir)
  21. {
  22. if ( ! file_exists($pathfile)) {
  23. throw new LogicException(sprintf('%s does not exists', $pathfile));
  24. }
  25. if ( ! is_dir($outputDir) || ! is_writable($outputDir)) {
  26. throw new LogicException(sprintf('%s is not writable', $outputDir));
  27. }
  28. $command = "-if " . escapeshellarg('$photoshopthumbnail') . " -b -PhotoshopThumbnail "
  29. . "-w " . escapeshellarg(realpath($outputDir) . '/PhotoshopThumbnail%c.jpg') . " -execute "
  30. . "-if " . escapeshellarg('$jpgfromraw') . " -b -jpgfromraw "
  31. . "-w " . escapeshellarg(realpath($outputDir) . '/JpgFromRaw%c.jpg') . " -execute "
  32. . "-if " . escapeshellarg('$previewimage') . " -b -previewimage "
  33. . "-w " . escapeshellarg(realpath($outputDir) . '/PreviewImage%c.jpg') . " -execute "
  34. . "-if " . escapeshellarg('$xmp:pageimage') . " -b -xmp:pageimage "
  35. . "-w " . escapeshellarg(realpath($outputDir) . '/XmpPageimage%c.jpg') . " "
  36. . "-common_args -q -m " . $pathfile;
  37. try {
  38. $this->exiftool->executeCommand($command);
  39. } catch (RuntimeException $e) {
  40. }
  41. return new \DirectoryIterator($outputDir);
  42. }
  43. }