| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 | <?php
namespace Gregwar\ImageBundle\Extensions;
use Symfony\Component\Templating\EngineInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Form\FormView;
/**
 * ImageTwig extension
 *
 * @author Gregwar <g.passault@gmail.com>
 * @author bzikarsky <benjamin.zikarsky@perbility.de>
 */
class ImageTwig extends \Twig_Extension
{
    private $container;
    private $environment;
    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;
    }
    
    public function initRuntime(\Twig_Environment $environment)
    {
        $this->environment = $environment;
    }
    public function getFunctions()
    {
        return array(
            'image' => new \Twig_Function_Method($this, 'image', array('is_safe' => array('html'))),
            'new_image' => new \Twig_Function_Method($this, 'newImage', array('is_safe' => array('html')))
        );
    }
    public function image($path)
    {
        return $this->container->get('image.handling')->open($path);
    }
    
    public function newImage($width, $height)
    {
        return $this->container->get('image.handling')->create($width, $height);
    }
    public function getName()
    {
        return 'image';
    }
}
 |