Last active
October 22, 2023 11:16
-
-
Save jenswittmann/3f32d59d240a73c1e8daff0699a3b424 to your computer and use it in GitHub Desktop.
MODX pdf2image Snippet
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 | |
# 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