IMagickSupport.php 807 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace OC\Preview;
  3. use OCP\ICache;
  4. use OCP\ICacheFactory;
  5. class IMagickSupport {
  6. private ICache $cache;
  7. private ?\Imagick $imagick;
  8. public function __construct(ICacheFactory $cacheFactory) {
  9. $this->cache = $cacheFactory->createLocal('imagick');
  10. if (extension_loaded('imagick')) {
  11. $this->imagick = new \Imagick();
  12. } else {
  13. $this->imagick = null;
  14. }
  15. }
  16. public function hasExtension(): bool {
  17. return !is_null($this->imagick);
  18. }
  19. public function supportsFormat(string $format): bool {
  20. if (is_null($this->imagick)) {
  21. return false;
  22. }
  23. $cached = $this->cache->get($format);
  24. if (!is_null($cached)) {
  25. return $cached;
  26. }
  27. $formatSupported = count($this->imagick->queryFormats($format)) === 1;
  28. $this->cache->set($format, $cached);
  29. return $formatSupported;
  30. }
  31. }