Created
October 4, 2018 20:43
-
-
Save netProphET/720b2833e88672f8ff022dc772a075d0 to your computer and use it in GitHub Desktop.
proof of concept for converting PDF to image in MODX Cloud
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 | |
/** | |
* Proof of Concept of PDF to image conversion, working in MODX Cloud | |
*/ | |
$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(100,100); | |
$im->readimage(MODX_BASE_PATH . $file . '[0]'); | |
$im->setImageFormat('jpeg'); | |
$im->writeImage($fullTargetFolderPath . '/' . $jpegFilename); | |
$im->clear(); | |
$im->destroy(); | |
return $targetFolder . '/' . $jpegFilename; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment