From 7dfd0a3235dcd75cd04f5c403e56eef522aff17b Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 19 Dec 2018 14:03:01 +0100 Subject: [PATCH] Enable ImageMagick during the setup if it is available See #2684 --- .../files/lib/system/WCFSetup.class.php | 12 +++++++++ .../adapter/ImagickImageAdapter.class.php | 26 ++++++++++++++----- .../PackageInstallationDispatcher.class.php | 7 +++++ wcfsetup/setup/lang/setup_de.xml | 2 ++ wcfsetup/setup/lang/setup_en.xml | 2 ++ .../template/stepShowSystemRequirements.tpl | 21 ++++++++++++++- 6 files changed, 63 insertions(+), 7 deletions(-) diff --git a/wcfsetup/install/files/lib/system/WCFSetup.class.php b/wcfsetup/install/files/lib/system/WCFSetup.class.php index 49da645fb1..9435ee8ca4 100644 --- a/wcfsetup/install/files/lib/system/WCFSetup.class.php +++ b/wcfsetup/install/files/lib/system/WCFSetup.class.php @@ -13,6 +13,7 @@ use wcf\system\database\MySQLDatabase; use wcf\system\devtools\DevtoolsSetup; use wcf\system\exception\SystemException; use wcf\system\exception\UserInputException; +use wcf\system\image\adapter\ImagickImageAdapter; use wcf\system\io\File; use wcf\system\io\Tar; use wcf\system\language\LanguageFactory; @@ -370,6 +371,16 @@ class WCFSetup extends WCF { } $system['gdLib']['result'] = (version_compare($system['gdLib']['value'], '2.0.0') >= 0); + // ImageMagick + $system['imagick'] = ['result' => false]; + if (ImagickImageAdapter::isSupported()) { + $system['imagick'] = [ + 'result' => true, + 'value' => ImagickImageAdapter::getVersion(), + ]; + $system['imagick']['supportsAnimatedGIFs'] = ImagickImageAdapter::supportsAnimatedGIFs($system['imagick']['value']); + } + // memory limit $system['memoryLimit']['value'] = ini_get('memory_limit'); $system['memoryLimit']['result'] = $this->compareMemoryLimit(); @@ -1271,6 +1282,7 @@ class WCFSetup extends WCF { SessionHandler::getInstance()->register('masterPassword', 1); SessionHandler::getInstance()->register('__wcfSetup_developerMode', self::$developerMode); SessionHandler::getInstance()->register('__wcfSetup_directories', self::$directories); + SessionHandler::getInstance()->register('__wcfSetup_imagick', ImagickImageAdapter::isSupported()); SessionHandler::getInstance()->unregister('__changeSessionID'); SessionHandler::getInstance()->update(); diff --git a/wcfsetup/install/files/lib/system/image/adapter/ImagickImageAdapter.class.php b/wcfsetup/install/files/lib/system/image/adapter/ImagickImageAdapter.class.php index 22dca0c877..f424843927 100644 --- a/wcfsetup/install/files/lib/system/image/adapter/ImagickImageAdapter.class.php +++ b/wcfsetup/install/files/lib/system/image/adapter/ImagickImageAdapter.class.php @@ -15,13 +15,13 @@ class ImagickImageAdapter implements IImageAdapter { * active color * @var \ImagickPixel */ - protected $color = null; + protected $color; /** * Imagick object * @var \Imagick */ - protected $imagick = null; + protected $imagick; /** * image height @@ -48,10 +48,7 @@ class ImagickImageAdapter implements IImageAdapter { public function __construct() { $this->imagick = new \Imagick(); - // check if writing animated gifs is supported - $version = $this->imagick->getVersion(); - preg_match('~([0-9]+\.[0-9]+\.[0-9]+)~', $version['versionString'], $match); - if (version_compare($match[0], '6.3.6') < 0) { + if (!static::supportsAnimatedGIFs(static::getVersion())) { $this->supportsWritingAnimatedGIF = false; } } @@ -425,4 +422,21 @@ class ImagickImageAdapter implements IImageAdapter { public static function isSupported() { return class_exists('\Imagick', false); } + + /** + * @return string + */ + public static function getVersion() { + preg_match('~(?P[0-9]+\.[0-9]+\.[0-9]+)~', \Imagick::getVersion()['versionString'], $match); + + return $match['version']; + } + + /** + * @param string $version + * @return bool + */ + public static function supportsAnimatedGIFs($version) { + return version_compare($version, '6.3.6') >= 0; + } } diff --git a/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php b/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php index 007a3ff1f1..1e94748c3e 100644 --- a/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php +++ b/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php @@ -284,6 +284,13 @@ class PackageInstallationDispatcher { } } + if (WCF::getSession()->getVar('__wcfSetup_imagick')) { + $statement->execute([ + 'imagick', + 'image_adapter_type', + ]); + } + // update options.inc.php OptionEditor::resetCache(); } diff --git a/wcfsetup/setup/lang/setup_de.xml b/wcfsetup/setup/lang/setup_de.xml index a4c1fa8052..26011e7741 100644 --- a/wcfsetup/setup/lang/setup_de.xml +++ b/wcfsetup/setup/lang/setup_de.xml @@ -30,6 +30,8 @@ + + diff --git a/wcfsetup/setup/lang/setup_en.xml b/wcfsetup/setup/lang/setup_en.xml index 7756c83e30..3dbe893595 100644 --- a/wcfsetup/setup/lang/setup_en.xml +++ b/wcfsetup/setup/lang/setup_en.xml @@ -31,6 +31,8 @@ + + diff --git a/wcfsetup/setup/template/stepShowSystemRequirements.tpl b/wcfsetup/setup/template/stepShowSystemRequirements.tpl index a500ec29d6..05609e746e 100644 --- a/wcfsetup/setup/template/stepShowSystemRequirements.tpl +++ b/wcfsetup/setup/template/stepShowSystemRequirements.tpl @@ -127,10 +127,29 @@ + +
+

{lang}wcf.global.systemRequirements.imagick{/lang}

+ +
+
+
{lang}wcf.global.systemRequirements.element.recommended{/lang}
+
{lang}wcf.global.systemRequirements.active{/lang}
+
+ +
+
{lang}wcf.global.systemRequirements.element.yours{/lang}
+
+ {$system.imagick.value} + {if !$system.imagick.result}{lang}wcf.global.systemRequirements.imagick.description{/lang}{/if} +
+
+
+
- + -- 2.20.1