Skip to content

Instantly share code, notes, and snippets.

@netProphET
Created June 8, 2016 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save netProphET/9c06290e1880ca69065ed4f78a9effa9 to your computer and use it in GitHub Desktop.
Save netProphET/9c06290e1880ca69065ed4f78a9effa9 to your computer and use it in GitHub Desktop.
PDF Thumbnailing in MODX - Proof of Concept
<?php
/**
* Warning: this code is for demonstration purposes only
*/
$file = $scriptProperties['file'];
$targetFolder = $modx->getOption('target', $scriptProperties, '/assets/images');
$fullTargetFolderPath = MODX_BASE_PATH . $targetFolder;
if (!preg_match("/\.pdf$/", $file)) {
return "PDF file not specified.";
}
$jpegFilename = basename($file, '.pdf') . '.jpg';
// instantiate Imagick
$im = new Imagick();
$im->setResolution(300,300);
$im->readimage(MODX_BASE_PATH . $file . '[0]');
$im->setImageFormat('jpeg');
$im->writeImage($fullTargetFolderPath . '/' . $jpegFilename);
$im->clear();
$im->destroy();
return $targetFolder . '/' . $jpegFilename;
<p>This shows the usage of a simple snippet to create a jpeg image from a PDF file.</p>
[[pdftojpeg? &file=`assets/pdfs/4826092553.pdf`]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment