PThumb is a Craft plugin that generates thumbnail preview images for PDF documents. It's easy to drop into your templates, requires only the commmand-line version of ImageMagick (not the PHP bindings), and caches the generated thumbnails.
It's still very much a work in progress, so use it in production environments at your own risk.
- Download the ZIP file
- Unzip it and move the
pthumb
folder tocraft/plugins
- Install the plugin from the Plugins page of your control panel
- Click on the PThumb link on the plugins page to configure the plugin
Setting | Description |
---|---|
Storage Path | Absolute or relative path to the storage directory for PDFs on the server, ex ~/craft/public/uploads/pdfs |
Base URL | URL to the storage path, ex /uploads/pdfs |
The craft.PThumb.thumbnail()
template tag returns a URL to the generated thumbnail.
<img src="{{ craft.PThumb.thumbnail(myAsset) }}">
<img src="{{ craft.PThumb.thumbnail(myAsset, 100, 100) }}">
<img src="{{ craft.PThumb.thumbnail(myAsset, 100, 150, true, 'jpg') }}">
The arguments, in order, are:
Argument | Description |
---|---|
Asset | Required |
Width | In pixels, default: 250 |
Height | In pixels, default: 250 |
Exact size | Force the canvas to exactly match the height /width specified by extending transparent (PNG) or white (JPG) space to the dimensions, useful for producing square images of rectangular documents, default: false |
File format | Options are 'png' or 'jpg', default: png |
- Files must be limited to a single directory
- Files must be stored locally
- Less configuration/more magic
- Better error handling
- Use IOHelper for file operations
- Use storage directory for thumbnails instead of public directory
- Support for S3, Rackspace Cloud Files, and Google Cloud Storage