damien
damien

Reputation: 23

symfony 2.1 : insert image with PHP script and Twig

With simple PHP we can insert an image generated by a PHP script, like :

<img src="image_script.php">

How can we do this with Symfony and Twig ?

Upvotes: 0

Views: 1615

Answers (2)

Sebastien Malot
Sebastien Malot

Reputation: 369

I think you should have a look at LiipImagineBundle :

https://github.com/liip/LiipImagineBundle

This bundle allows you to create a cache of resized images.

Upvotes: 0

Maerlyn
Maerlyn

Reputation: 34107

You can do it in Symfony2 and twig almost like in plain php:

<img src="{{ path("img_action") }}" alt="" />

where img_action is the route name for the action that returns an image.

In that action, create a new Response instance, set its contents to the image, set the content-type header to the appropriate MIME type, then return it.

Upvotes: 2

Related Questions