Skip to content

Instantly share code, notes, and snippets.

@jenswittmann
Last active October 22, 2023 11:16
Show Gist options
  • Save jenswittmann/3f32d59d240a73c1e8daff0699a3b424 to your computer and use it in GitHub Desktop.
Save jenswittmann/3f32d59d240a73c1e8daff0699a3b424 to your computer and use it in GitHub Desktop.
MODX pdf2image Snippet
<?php
# vars
$filePath = $modx->getOption('input', $scriptProperties, '');
$savePath = "assets/components/phpthumbof/cache/poster_" . md5($filePath) . ".jpg";
# check file exists and is PDF
if (!file_exists(MODX_BASE_PATH . $filePath) || mime_content_type(MODX_BASE_PATH . $filePath) != "application/pdf") {
return $filePath;
}
# generate image
if (!file_exists(MODX_BASE_PATH . $savePath)) {
$imagick = new Imagick();
$imagick->readImage(MODX_BASE_PATH . $filePath);
$imagick->writeImage(MODX_BASE_PATH . $savePath);
$imagick->clear();
$imagick->destroy();
}
return $savePath;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment