Skip to content

Instantly share code, notes, and snippets.

@bwente
Created January 14, 2020 20:32
Show Gist options
  • Save bwente/a566e5a5b4327631840ba7cd4f7ad66f to your computer and use it in GitHub Desktop.
Save bwente/a566e5a5b4327631840ba7cd4f7ad66f to your computer and use it in GitHub Desktop.
[[!getImage? &path=`/images/` &image=`email_hero.jpg` &options=`&w=540` ]]
<?php
$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