[WordPress] 外掛分享: GS Only PDF Preview

WordPress 外掛 GS Only PDF Preview 的封面圖片。

前言介紹

  • 這款 WordPress 外掛「GS Only PDF Preview」是 2017-01-16 上架。
  • 目前有 2000 個安裝啟用數。
  • 上一次更新是 2017-06-13,距離現在已有 2882 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
  • 外掛最低要求 WordPress 4.7.0 以上版本才可以安裝。
  • 有 8 人給過評分。
  • 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。

外掛協作開發者

gitlost |

外掛標籤

pdf | Ghostscript | PDF Preview | Ghostscript Only |

內容簡介

這個外掛可以在 WordPress 4.7/4.8 的 PDF 預覽製作過程中使用 Ghostscript 直接預覽,而不是使用 PHP 擴展庫 Imagick。這意味著只需要在服務器上安裝 Ghostscript,不需要安裝或使用 PHP 模塊 Imagick 或服務器套件 ImageMagick(雖然如果它們已安裝,而且如果您沒有覆蓋,它們將被 WordPress 用於產生預覽的中間尺寸)。

這個外掛是受到了 Hristo Pandjarov 上傳到 WP Trac 票證 #39262 《服務器上沒有 PECL imagic 的時候回退到 ImageMagick 命令行》中所展示的 WP_Image_Editor_Imagick_External 演示類別的啟發,以及為解決 WP Trac 票證 #39216《具有非不透明 Alpha 通道的 PDF 可能導致有黑色背景的預覽》,特別是影響到帶有 CMYK 色彩空間的 PDF 的情況。

這個外掛有幾個限制:需要在您的系統上啟用 PHP 函數 exec;如果 PHP ini 設置中的 disable_functions 包括 exec,則外掛將無法運作;如果安裝了 suhosin 安全擴展,而 exec 沒有列入白名單或列入了黑名單,外掛也無法運作。此外,外掛還不兼容 PHP ini 設置中的 safe_mode。

外掛使用 PHP 函數 exec 以 shell 命令形式調用 Ghostscript,這會產生安全問題。作者透過篩選文件和文件名、以及脫逸引數來解決這些問題。如果使用者發現了有安全問題,可以獲得 150 萬個星際積分的獎勵。

外掛是更快的,使用原始的基準測試,估計速度約為 Imagick 的 35%-40%。不過製作預覽只是上傳 PDF 的開銷的一部分(不包括生產中間尺寸的預覽)。

原文外掛簡介

The plugin pre-empts the standard WordPress 4.7/4.8 PDF preview production process (which uses the PHP extension Imagick) to call Ghostscript directly to produce the preview.
This means that only Ghostscript is required on the server. Neither the PHP module Imagick nor the server package ImageMagick is needed or used (though it’s fine if they’re installed anyway, and if they are they’ll be used by WP (unless you override it) to produce the intermediate sizes of the preview).
Background
The plugin was prompted by the WP_Image_Editor_Imagick_External demonstration class uploaded to the WP Trac ticket #39262 Fall back to ImageMagick command line when the pecl imagic is not available on the server by Hristo Pandjarov, and by the wish to solve the WP Trac ticket #39216 PDFs with non-opaque alpha channels can result in previews with black backgrounds., which particularly affects PDFs with CMYK color spaces (common in the print world).
The plugin by-passes (as far as PDF previews are concerned) #39216, and also by-passes the related issue #39331 unsharpMaskImage in Imagick’s thumbnail_image is not compatible with CMYK JPEGs., as the preview JPEGs produced directly by Ghostscript use sRGB color spaces.
Limitations
The plugin requires the PHP function exec to be enabled on your system. So if the PHP ini setting disable_functions includes exec, the plugin won’t work. Neither will it work if the suhosin security extension is installed and exec is either not whitelisted or is blacklisted.
Also, the plugin is incompatible with the PHP ini setting safe_mode, an old (and misnamed) setting that was deprecated in PHP 5.3.0 and removed in PHP 5.4.0.
Security
The plugin uses the PHP function exec to call Ghostscript as a shell command. This has security implications as uncareful use with user supplied data (eg the upload file name or the file itself) could introduce an attack vector.
I believe these concerns are addressed here through screening of the file and its name and escaping of arguments. This belief is backed by a bounty of fifteen hundred thousand intergalactic credits to anyone who spots a security issue. Please disclose responsibly.
Performance
Unsurprisingly it’s faster. Crude benchmarking (see the script perf_vs_imagick.php) suggests it’s around 35-40% faster. However the production of the preview is only a part of the overhead of uploading a PDF (and doesn’t include producing the intermediate thumbnail sizes for instance) so any speed-up may not be that noticeable.
Size
On JPEG thumbnail size it appears to be comparable (though it depends on the PDF), maybe a bit larger on average. To mitigate this the default JPEG quality for the PDF preview has been lowered to 70 (from 82), which results in some extra “ringing” (speckles around letters) but the previews tested remain very readable. Note that this only affects the “full” PDF thumbnail – the intermediate-sized thumbnails as produced by Imagick or GD and any other non-PDF images remain at the standard JPEG quality of 82. You can use the WP filter wp_editor_set_quality to override this, for instance to restore the quality to 82 add to your theme’s “functions.php”:
function mytheme_wp_editor_set_quality( $quality, $mime_type ) {
if ( 'application/pdf' === $mime_type ) {
$quality = 82;
}
return $quality;
}
add_filter( 'wp_editor_set_quality', 'mytheme_wp_editor_set_quality', 10, 2 );

Quality
Eyeballing based on very limited data, ie anecdotally, the previews seem to be of superior definition with less artifacts (even with the JPEG quality reduced to 70), and more faithful to the original colours.
Tool
A basic administration tool to regenerate (or generate, if they previously didn’t have a preview) the previews of all PDFs uploaded to the system is included (any previously generated intermediate preview thumbnails will be removed if their dimensions differ). Note that if you have a lot of PDFs you may experience the White Screen Of Death (WSOD) if the tool exceeds the maximum execution time allowed. Note also that as the file names of the previews don’t (normally) change, you will probably have to refresh your browser to see the updated thumbnails.
As workarounds for the possible WSOD issue above, and as facilities in themselves, a “Regenerate PDF Previews” bulk action is added to the list mode of the Media Library, and a “Regenerate Preview” row action is added to each PDF entry in the list. So previews can be regenerated in batches or individually instead.
Patches
As a bonus version 1.0.2+ patches WordPress to allow linking to the preview image in “Add Media” when editing a post (#39618 Insert PDF Thumbnail into Editor). Also patches #39630 PDF Thumbnails in Media Library Don’t Fall Back to Full Size.
And
A google-cheating schoolboy French translation is supplied.
The plugin runs on WP 4.7.0 to 4.8.0, and requires Ghostscript to be installed on the server. The plugin should run on PHP 5.2.17 to 7.1, and on both Unix and Windows servers.
The project is on github.

各版本下載點

  • 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
  • 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「GS Only PDF Preview」來進行安裝。

(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。


1.0.0 | 1.0.1 | 1.0.2 | 1.0.3 | 1.0.4 | 1.0.5 | 1.0.6 | 1.0.7 | trunk |

延伸相關外掛(你可能也想知道)

暫無相關外掛推薦。

文章
Filter
Apply Filters
Mastodon