Skip to content

Instantly share code, notes, and snippets.

@bwente
Created January 14, 2020 20:33
Show Gist options
  • Save bwente/3a568f3b06a92db35e31fad86074b031 to your computer and use it in GitHub Desktop.
Save bwente/3a568f3b06a92db35e31fad86074b031 to your computer and use it in GitHub Desktop.
Run pthumb and return image
<?php
// [[!getImage? &path=`/images/` &image=`email_hero.jpg` &options=`&w=540`]]
$path = $modx->getOption('path', $scriptProperties, '');
$image = $modx->getOption('image', $scriptProperties, '');
$options = $modx->getOption('options', $scriptProperties, '');
$resizer = $modx->getOption('useResizer', $scriptProperties, 1);
$imagePath = $modx->runSnippet('pthumb', array(
'input' => $path.$image,
'options' => $options,
'useResizer' => $resizer
));
if ($path.$image == $imagePath) {
$modx->log(modX::LOG_LEVEL_ERROR, 'image not found!');
} else {
$url = $modx->config['site_url'];
$imageUrl = $url.$imagePath;
$imageMime = image_type_to_mime_type(exif_imagetype($imageUrl));
$fp = fopen($imageUrl, 'rb');
header('Content-Type: '.$imageMime);
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
fpassthru($fp);
}
exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment