-
-
Save netProphET/9c06290e1880ca69065ed4f78a9effa9 to your computer and use it in GitHub Desktop.
PDF Thumbnailing in MODX - Proof of Concept
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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