Zend Framework

If you need to return an image, simply return the response object filled in with the content: that will tell the Zend\Mvc\Application to entirely skip the Zend\Mvc\MvcEvent::EVENT_RENDER event and go to Zend\Mvc\Application::EVENT_FINISH

Example code:

public function displayAction()
{
    // get image content
    $response = $this->getResponse();

    $response->setContent($imageContent);
    $response
        ->getHeaders()
        ->addHeaderLine('Content-Transfer-Encoding', 'binary')
        ->addHeaderLine('Content-Type', 'image/png')
        ->addHeaderLine('Content-Length', mb_strlen($imageContent));

    return $response;
}

 

This will cause the application to direcly go to the Zend\Mvc\Event::EVENT_FINISH, which in turn is capable of sending the response to the output.