diff options
author | Robin Appelman <robin@icewind.nl> | 2023-02-08 11:48:33 +0100 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2023-02-13 14:57:06 +0100 |
commit | 382432d4e1a9c83063ae7d2a2b33491540a3a84d (patch) | |
tree | 59c3a1f80930e798a7320eecb81f1f16251bf5f8 /lib/private/Preview/IMagickSupport.php | |
parent | 6236235d23ada9f6e141f7489bd5ff069dc89c9d (diff) | |
download | nextcloud-server-382432d4e1a9c83063ae7d2a2b33491540a3a84d.tar.gz nextcloud-server-382432d4e1a9c83063ae7d2a2b33491540a3a84d.zip |
cache formats supported by imagick
turns out this can be quite slow
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private/Preview/IMagickSupport.php')
-rw-r--r-- | lib/private/Preview/IMagickSupport.php | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/private/Preview/IMagickSupport.php b/lib/private/Preview/IMagickSupport.php new file mode 100644 index 00000000000..e22ae93ab94 --- /dev/null +++ b/lib/private/Preview/IMagickSupport.php @@ -0,0 +1,40 @@ +<?php + +namespace OC\Preview; + +use OCP\ICache; +use OCP\ICacheFactory; + +class IMagickSupport { + private ICache $cache; + private ?\Imagick $imagick; + + public function __construct(ICacheFactory $cacheFactory) { + $this->cache = $cacheFactory->createLocal('imagick'); + + if (extension_loaded('imagick')) { + $this->imagick = new \Imagick(); + } else { + $this->imagick = null; + } + } + + public function hasExtension(): bool { + return !is_null($this->imagick); + } + + public function supportsFormat(string $format): bool { + if (is_null($this->imagick)) { + return false; + } + + $cached = $this->cache->get($format); + if (!is_null($cached)) { + return $cached; + } + + $formatSupported = count($this->imagick->queryFormats($format)) === 1; + $this->cache->set($format, $cached); + return $formatSupported; + } +} |