从symfony 1.4翻译成symfony2

Hello I have a code that is returning an image decoded on base64, but that code is on the version 1.4 of symfony and I need use that on the version 2.

Here is my code:

$imageData = $registro[0]['imagen'];   
$response = $this->getResponse();
$response->clearHttpHeaders();
$response->setContentType('image/png');
$response->setContent(base64_decode($imageData));
return sfView:NONE

Hello I have solved that.

The solution is:

The controller side:

    ob_start();
    imagepng($im);
    $imagen = base64_encode(ob_get_contents());
    imagedestroy($im);
    ob_get_clean();
    $response = new Response();
    $response->headers->set('Content-Type', 'image/png');
    $response->setContent($imagen);
    return $response;

The twig side:

<img class="img-responsive " width="200px" id="imagen-perfil" style="display: block;"  
                     src="data:image/png;base64,{{  render(controller( 'Bundle:Controller:function', { 'variable' : resource } )) }}" />
$imageData = $registro[0]['imagen'];   
$response = new Response();
$response->headers->set('Content-Type', 'image/png');
$response->setContent(base64_decode($imageData));            

return $response;

Assuming knowing what $registro contains is not important.