Created
May 29, 2014 06:41
-
-
Save leviwheatcroft/e13df8cdbbf03592d71c to your computer and use it in GitHub Desktop.
working with phpthumbof in modx to get at the raw file contents and output it directly.
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 | |
// after I figured this out I realised I could just use mun.ee | |
// you probably should too! | |
if (!$modx) die(); | |
$debug = 0 || $_GET['debug']; | |
if ($debug) require_once($modx->config['base_path'] . 'assets/php/kint-0.9/Kint.class.php'); | |
$options = array( | |
'id' => 0, | |
'defaultImages' => array(50,51,52,53,54,55,56,57), | |
'width' => 900, | |
'height' => 556, | |
'blur' => 0, //set to '0' for no blur | |
'clrSat' => 0, //set to '0' for no color | |
'clrHex' => 'FFFFFF' | |
); | |
$options = array_merge($options, $_GET); | |
if (!$options['id']) { | |
print("no id"); | |
die(); | |
} | |
//get specified image or choose a default | |
$resource = $modx->getObject('modResource', $options['id']); | |
$src = $resource->getTVValue('coverImage'); | |
if (!$src) { | |
$defaultImage = $options['id'] % count($options['defaultImages']); | |
$defaultImage = $options['defaultImages'][$defaultImage]; | |
$defaultImage = $modx->getObject('modResource', $defaultImage); | |
$src = $defaultImage->getSourceFile(); | |
} | |
//assemble phpthumbof options | |
$phpThumbOpts = ''; | |
$phpThumbOpts .= '&zc=1&aoe=1'; | |
$phpThumbOpts .= '&w=' . $options['width']; | |
$phpThumbOpts .= '&h=' . $options['height']; | |
if ($options['blur']) $phpThumbOpts .= '&fltr[]=blur|' . $options['blur']; | |
if ($options['clrSat']) $phpThumbOpts .= '&fltr[]=clr|' . $options['clrSat'] . '|' . $options['clrHex']; | |
//run phpthumbof | |
$args = array( | |
'input' => $src, | |
'options' => $phpThumbOpts | |
); | |
$src = $modx->runSnippet('phpThumbOf', $args); | |
//translate path | |
$src = preg_replace("/(.*assets\/)/", "", $src); | |
$src = $modx->config['assets_path'] . $src; | |
//debug | |
if ($debug) { | |
d($options); | |
d(array($src, $args)); | |
die(); | |
} | |
//output | |
$im = imagecreatefromjpeg($src); | |
header('Content-Type: image/jpeg'); | |
imagejpeg($im); | |
die(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment