/** * Uses WP_Image_Editor_Imagick to generate thumbnails. * * @param int $ID The attachment ID to retrieve thumbnail from. * @param int $pg The page to get the thumbnail of. * * @return bool|string False on failure, URL to thumb on success. */ public function getThumbnail($ID, $pg = 1) { $doc_path = get_attached_file($ID); $img = new DG_Image_Editor_Imagick($doc_path, $pg - 1); $err = $img->load(); if (is_wp_error($err)) { DG_Logger::writeLog(DG_LogLevel::Error, __('Failed to open file in Imagick: ', 'document-gallery') . $err->get_error_message()); return false; } $temp_file = DG_Util::getTempFile(); $err = $img->save($temp_file, 'image/png'); if (is_wp_error($err)) { DG_Logger::writeLog(DG_LogLevel::Error, __('Failed to save image in Imagick: ', 'document-gallery') . $err->get_error_message()); return false; } return $temp_file; }
/** * Uses WP_Image_Editor_Imagick to generate thumbnails. * * @param int $ID The attachment ID to retrieve thumbnail from. * @param int $pg The page to get the thumbnail of. * * @return bool|string False on failure, URL to thumb on success. */ public static function getImagickThumbnail($ID, $pg = 1) { include_once DG_PATH . 'inc/class-image-editor-imagick.php'; $doc_path = get_attached_file($ID); $img = new DG_Image_Editor_Imagick($doc_path, $pg - 1); $err = $img->load(); if (is_wp_error($err)) { DG_Logger::writeLog(DG_LogLevel::Error, __('Failed to open file in Imagick: ', 'document-gallery') . $err->get_error_message()); return false; } $temp_file = self::getTempFile(); $err = $img->save($temp_file, 'image/png'); if (is_wp_error($err)) { DG_Logger::writeLog(DG_LogLevel::Error, __('Failed to save image in Imagick: ', 'document-gallery') . $err->get_error_message()); return false; } return $temp_file; }