Skip to content

Instantly share code, notes, and snippets.

@netProphET
Created October 4, 2018 20:43
Show Gist options
  • Save netProphET/720b2833e88672f8ff022dc772a075d0 to your computer and use it in GitHub Desktop.
Save netProphET/720b2833e88672f8ff022dc772a075d0 to your computer and use it in GitHub Desktop.
proof of concept for converting PDF to image in MODX Cloud
<?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