/** * Detects and return the name of the first supported editor which can either be "Imagick" or "Gd". * * @param array $editorList Array of editor list names. Use this to change the order of evaluation for editors for this function call only. Default order of evaluation is Imagick then GD. * * @return string Name of available editor. * @throws \Exception Throws exception if there are no supported editors. */ public static function detectAvailableEditor($editorList = null) { if (null === $editorList) { $editorList = self::$editorList; } /* Get first supported editor instance. Order of editorList matter. */ foreach ($editorList as $editorName) { if ('Imagick' === $editorName) { $editorInstance = new ImagickEditor(); } else { $editorInstance = new GdEditor(); } /** @var EditorInterface $editorInstance */ if (true === $editorInstance->isAvailable()) { return $editorName; } } throw new \Exception('No supported editor.'); }