php - Symfony2 - base64_decode in twig -


i need display picture in twig template. picture in controller string encoded in base64, created personal function in service decode base64 :

public function base64toimg($base64) {     $img_str = 'image/png;base64,'.$base64;     $img_data = explode(";",$img_str);     $type_img = $img_data[0];     $final_img = explode(",",$img_data[1]);     header("content-type:".$type_img);      return base64_decode($final_img[1]); } 

and in controller :

$logo = $this->container->get('services.utils')->base64toimg($mydata); echo $logo; die(); 

it works, when send $logo template render, picture isn't displayed {{ logo }}. tried create own twig function doesn't works also...

there solution ?

thanks

how trying display image inside template? if use base64encoded string you'd need data:image/png;base64,encoded string in image tag.

<img alt="embedded image" src="data:image/png;base64,ivborw0kggoaaaansuheugaaadia..." /> 

other options saving file or using script display image

<img alt="embedded image" src="/controller/image?id=foo" /> 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -