/** * Output image of given size for an sfImagePoolImage. * * @param mixed $invoker Model or sfImagePool image * @param string $dimensions e.g. 'crop=200x150' or '200' for fit to 200 width (scale is default) * @param mixed $options either string or array, e.g. array('method' => 'scale', 'require_size' => true) * @param string $attributes HTML attributes, such as width, height and alt * @param boolean $absolute return absolute URL for an image * @return string * @author Jimmy Wong */ function pool_image_tag($invoker, $dimensions = 200, $options = 'crop', $attributes = array(), $absolute = false) { // remove Symfony escaping if applied if ($invoker instanceof sfOutputEscaper) { $invoker = $invoker->getRawValue(); } // attempt to fetch associated sfImagePoolImage $image = $invoker instanceof sfImagePoolImage ? $invoker : $invoker->getFeaturedImage(); if (is_array($dimensions)) { $w = $dimensions[0]; $h = $dimensions[1]; } else { if (strpos(strtolower($dimensions), 'x') !== false) { list($w, $h) = explode('x', $dimensions); } else { $h = $w = $dimensions; } } if (is_array($options)) { $method = array_key_exists('method', $options) ? $options['method'] : 'crop'; } else { $method = $options; $options = array(); } $pool_image_uri = pool_image_uri($image, array($w, $h), $method, $absolute); // We need the actual image dimensions so the space is correct on the page if (array_key_exists('require_size', $options) && true == $options['require_size']) { // Only if we're scaling it - get the image size if ('scale' == $method) { list($attributes['width'], $attributes['height']) = sfImagePoolUtil::calculateWidthAndHeight($image, $w, $h); } else { $attributes['width'] = $w; $attributes['height'] = $h; } } $attributes = _sf_image_pool_build_attrs($image, array($w, $h), $method, $attributes); return image_tag($pool_image_uri, $attributes); }
<?php if ($object->allowSelectMultiple()) { ?> <?php if (count($object->getPoolImages()->getUnfeatured()) > 1) { ?> <ul class="gallery"> <?php foreach ($object->getPoolImages()->getUnfeatured() as $i) { ?> <?php if ($i['filename']) { ?> <li><?php echo link_to(pool_image_tag($i, '50x50'), pool_image_uri($i, '468x315', 'crop')); ?> </li> <?php } ?> <?php } ?> </ul> <?php } ?> <div class="featured-image"><?php echo pool_image_tag($object->getFeaturedImage(), '468x315');
echo pool_image_tag($object->getFeaturedImage(), '720x250', 'crop'); ?> </div> <?php if (count($object->getPoolImages()->getUnfeatured())) { ?> <ul class="sf_image_pool_gallery_admin"> <?php foreach ($object->getPoolImages()->getUnfeatured() as $i) { ?> <?php if ($i['filename']) { ?> <li><?php echo link_to(pool_image_tag($i, '50x50'), pool_image_uri($i, '720x250', 'crop')); ?> </li> <?php } ?> <?php } ?> </ul> <?php } ?> <?php } else {
/** * Fetch URL to the default pool image. * * @todo Move the logic from the pool_image_uri() into this method and then * call this method from the helper for backwards compatibility. * * @return string */ public function getDefaultPoolImageUrl($dimensions = '100x100', $method = 'crop', $absolute = false, Doctrine_Record $object = null) { $object = is_null($object) ? $this->getInvoker() : $object; // get main image $image = $this->getPoolImages($object)->getFeatured(); // return url for the image return pool_image_uri($image, $dimensions, $method, $absolute); }