[[!getResourceField? &id=`[[+id]]` &field=`blogImage`]]
{"gal_src":"http://localhost/sos_dev/assets/components/gallery/files/2010/10/pic-02.png","gal_id":2,"gal_name":"Photo 02","gal_description":"Interesting photo 02.","gal_image_width":"500","gal_image_height":"280","gal_orig_width":1313,"gal_orig_height":760,"gal_album":"1","gal_watermark-text":"","gal_watermark-text-position":"BL","gal_other":"","gal_rotate":"0","gal_sizer":100,"gal_cropCoords":"{\"left\":0,\"right\":502,\"top\":0,\"bottom\":352,\"relRight\":0,\"relBottom\":0,\"on\":true}","gal_cropTop":0,"gal_cropRight":0,"gal_cropBottom":0,"gal_cropLeft":0}
&processTVs=`1`
[[+tv.blogImage:image]]
[[!GalleryItem? &id=`12`]]
[[!GalleryItem? &id=`[[*galleryItemID]]`]]
<?php /** * galleryImageGenerator * * 2014 by Toby Trembath <http://twobyte.com> * * Built upon the excellent Gallery Package by Shaun McCormick <[email protected]> * * DESCRIPTION * * This Snippet uses galleryItem TV and formats appropriately for template position. * IMPORTANT, Output options for your GalleryItem TV *Must* be set to string * * PROPERTIES: * * &TVstring string containing TV values as JSON required * &width integer optional. * &height integer optional. * * Dependent on the excellent Gallery and PHPThumb Packages * * USAGE: * * [[galleryImageGenerator? &TVstring=`[[*featureImage]]` &width=`296`]] * Requires Chunk called photo-pic to render <img>, todo: make this a tpl property */ /* example &TVstring json we will pass in.. { "gal_src":"/assets/gallery/3/34.jpg", "gal_id":34, "gal_name":"Cool Kitchen title", "gal_description":"Cool Kitchen Alt", "gal_image_width":1270, "gal_image_height":847, "gal_orig_width":3735, "gal_orig_height":2490, "gal_album":"3", "gal_watermark-text":"", "gal_watermark-text-position":"BL", "gal_other":"", "gal_rotate":"0", "gal_sizer":"34", "gal_cropCoords":"{\"left\":0,\"right\":762,\"top\":128,\"bottom\":849,\"relRight\":508,\"relBottom\":0,\"on\":true}", "gal_cropTop":128, "gal_cropRight":508, "gal_cropBottom":0, "gal_cropLeft":0 } */ $TVstring = $modx->getOption('TVstring', $scriptProperties); $width = (int) $modx->getOption('width', $scriptProperties); $height = (int) $modx->getOption('height', $scriptProperties); if (!$TVstring){ $modx->log(modX::LOG_LEVEL_ERROR, '[galleryImageGenerator] $TVstring "'.$TVstring.'" not understood!'); return; } // Taken from the GalleryItem output script, except value changed to be $TVstring $corePath = $modx->getOption('gallery.core_path',null,$modx->getOption('core_path').'components/gallery/'); $modx->addPackage('gallery',$corePath.'model/'); if (!empty($TVstring) && $TVstring != '{}') { $data = $modx->fromJSON($TVstring); if (empty($data)) return ''; $item = $modx->getObject('galItem',$data['gal_id']); if ($item) { /* get filters */ $filtersArray = array(); if (!empty($data['gal_rotate'])) { $filtersArray['rot'] = (string)$data['gal_rotate']; } /* text watermark */ if (!empty($data['gal_watermark-text'])) { $filtersArray['wmt'] = (string)$data['gal_watermark-text'].'|5|'.$data['gal_watermark-text-position'].'|ffffff|||5|||100|0'; } /* get any other params */ $other = !empty($data['gal_other']) ? $data['gal_other'] : ''; if (!empty($other)) { if (substr($other,0,1) != '&') { $other = '&'.$other; } } $dimensions = array(); $data['gal_cropLeft'] = !empty($data['gal_cropLeft']) ? $data['gal_cropLeft'] : 0; $data['gal_cropTop'] = !empty($data['gal_cropTop']) ? $data['gal_cropTop'] : 0; $data['gal_cropRight'] = !empty($data['gal_cropRight']) ? $data['gal_cropRight'] : 0; $data['gal_cropBottom'] = !empty($data['gal_cropBottom']) ? $data['gal_cropBottom'] : 0; if(!empty($width) && $width > 0){ //$dimensions['w']=$width; $scale = ( $data['gal_image_width'] - $data['gal_cropLeft'] - $data['gal_cropRight'] )/$width; $dimensions['w'] = round($data['gal_image_width']/$scale); } if(!empty($height) && $height > 0){ //$dimensions['h']=$height; $scale = ( $data['gal_image_height'] - $data['gal_cropTop'] - $data['gal_cropBottom'] )/$height; $dimensions['h'] = round($data['gal_image_height']/$scale); } if(count($dimensions)==0){ $dimensions = array( 'w' => $data['gal_image_width'], 'h' => $data['gal_image_height'] ); $scale = 1; } $dimensions['f'] = 'png'; /* crop */ if (!empty($data['gal_cropCoords'])) { $filtersArray['crop'] = round($data['gal_cropLeft']/$scale).'|'.round($data['gal_cropRight']/$scale).'|'.round($data['gal_cropTop']/$scale).'|'.round($data['gal_cropBottom']/$scale); } $filters = ''; foreach ($filtersArray as $filter => $val) { $filters .= '&fltr[]='.$filter.'|'.$val; } $url = $item->get('image',$dimensions).$filters.$other; $props = array ( 'thumbnail' => $url, 'url' => $url, 'name' => $data['gal_description'], 'alt' => $data['gal_description'], 'title' => $data['gal_name'], 'class' => $data['gal_class'] ); $value = $modx->getChunk('photo-pic', $props); } else { $value = ''; } } else { /* if empty dont return json, return blank */ $value = ''; } return $value; ?>