-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
turns out this can be quite slow Signed-off-by: Robin Appelman <robin@icewind.nl>
- Loading branch information
1 parent
6236235
commit cbf7e48
Showing
3 changed files
with
51 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters