WPThumbs
Themes Plugins By purpose By industry Best-of lists Fix it guides
Free Plugin by bonger v1.0.7

GS Only PDF Preview

Uses Ghostscript directly to generate PDF previews.

GS Only PDF Preview

The facts

Rating
5★ from 8
Active installs
1k+
Price
Free
Last updated
13 Jun 2017
Added
Jan 2017
Requires WP
4.7.0
Tested up to
WP 4.8.0
Downloads
15,040

Our analysis

AI-assisted

GS Only PDF Preview is a WordPress plugin that enables the generation of PDF previews by directly calling Ghostscript, bypassing the standard Imagick method. This approach allows users to create previews without needing the Imagick PHP extension or the ImageMagick server package, although these can still be present on the server. The plugin aims to resolve specific issues related to PDF previews, particularly those involving non-opaque alpha channels and CMYK color spaces, which are common in print materials.

This plugin is suitable for users who need to generate PDF previews on their WordPress sites while relying solely on Ghostscript. It requires the PHP function exec to be enabled and is not compatible with certain PHP settings, which may limit its use in some environments.

Best for: This plugin suits WordPress users needing efficient PDF previews without Imagick.

What it does well

  • Utilises Ghostscript for PDF previews
  • Bypasses issues with Imagick related to CMYK PDFs
  • Does not require Imagick or ImageMagick
  • Faster than the standard Imagick method

Where it falls short

  • Requires exec function to be enabled
  • Incompatible with safe_mode setting
  • Potential security implications from using exec

Verdict

GS Only PDF Preview provides a specific solution for generating PDF previews using Ghostscript, though it has limitations regarding server configurations and security considerations.

From the developer

bonger's own description of GS Only PDF Preview, lightly tidied.

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 );

Read the full description on the official page →

Tagged as

Alternatives

Other plugins for securing a site.

Really Simple Security

Easily improve site security with WordPress Hardening, Two-Factor Authentication (2FA), Login Protection, Vuln...

Free 3M+ installs 4.9★ (8,862)
Wordfence Security

Firewall, Malware Scanner, Two Factor Auth, and Comprehensive Security Features, powered by our 24-hour team....

Free 5M+ installs 4.7★ (4,983)
Akismet Anti-spam: Spam Protection

The best anti-spam protection to block spam comments and spam in a contact form. The most trusted antispam sol...

Free 5M+ installs 4.7★ (1,186)
Loginizer

Loginizer is a WordPress security plugin which helps you fight against bruteforce attacks.

Free 1M+ installs 4.8★ (1,030)
Safe SVG

Enable SVG uploads and sanitize them to stop XML/SVG vulnerabilities in your WordPress website.

Free 1M+ installs 4.9★ (79)
All-In-One Security

Protect your website investment with All-In-One Security (AIOS) – a comprehensive and easy to use security plu...

Free 1M+ installs 4.7★ (1,715)