/** * Initialize file formats supported by IMagick. */ private static function initFileFormats() { if (!self::isImagickAvailable() || !(self::$file_formats = DG_Image_Editor_Imagick::query_formats())) { self::$file_formats = array(); } $image_exts = array('jpg', 'jpeg', 'gif', 'png'); self::$file_formats = array_map('strtolower', array_diff(self::$file_formats, $image_exts)); }
/** * @filter dg_thumbers Allows developers to filter the Thumbers used * for specific filetypes. Index is the regex to match file extensions * supported and the value is anything that can be accepted by call_user_func(). * The function must take two parameters, 1st is the int ID of the attachment * to get a thumbnail for, 2nd is the page to take a thumbnail of * (may not be relevant for some filetypes). * * @return array */ private static function getThumbers() { static $thumbers = null; if (is_null($thumbers)) { $options = self::getOptions(); $active = $options['active']; $thumbers = array(); // Audio/Video embedded images if ($active['av']) { $exts = implode('|', self::getAudioVideoExts()); $thumbers[$exts] = array(__CLASS__, 'getAudioVideoThumbnail'); } // Ghostscript if ($active['gs'] && self::isGhostscriptAvailable()) { $exts = implode('|', self::getGhostscriptExts()); $thumbers[$exts] = array(__CLASS__, 'getGhostscriptThumbnail'); } // Imagick if ($active['imagick'] && self::isImagickAvailable()) { include_once DG_PATH . 'inc/class-image-editor-imagick.php'; if ($exts = DG_Image_Editor_Imagick::query_formats()) { $exts = implode('|', $exts); $thumbers[$exts] = array(__CLASS__, 'getImagickThumbnail'); } } // allow users to filter thumbers used $thumbers = apply_filters('dg_thumbers', $thumbers); // strip out anything that can't be called $thumbers = array_filter($thumbers, 'is_callable'); // log which thumbers are being used if (DG_Logger::logEnabled()) { if (count($thumbers) > 0) { $entry = __('Thumbnail Generators: ', 'document-gallery'); foreach ($thumbers as $k => $v) { $thumber = is_array($v) ? implode('::', $v) : print_r($v, true); // TODO: The following works for all internal regexes, but may have unpredictable // results if developer adds additional thumbnail generators using different regexes $filetypes = str_replace('|', ', ', $k); $entry .= PHP_EOL . "{$thumber}: {$filetypes}"; } } else { $entry = __('No thumbnail generators enabled.', 'document-gallery'); } DG_Logger::writeLog(DG_LogLevel::Detail, $entry); } } return $thumbers; }