Output image src via JSON I have worked out how to use dynamic routing and JsonResponse() in a custom controller to output pure JSON, with no HTML at all. I would like to do the same with an image — for the page to output an image header and the image itself to the browser, with no HTML, as though the address were simply a file path to an image.

Is this possible?
Something like the following could help you.

Just Set $filepath  and $filename with your desired values.

$filepath = "/path/to/my/image/chart.png";
$filename = "chart.png";

$response = new Response();
$disposition = $response-&gt;headers-&gt;makeDisposition(ResponseHeaderBag::DISPOSITION_INLINE, $filename);
$response-&gt;headers-&gt;set('Content-Disposition', $disposition);
$response-&gt;headers-&gt;set('Content-Type', 'image/png');
$response-&gt;setContent(file_get_contents($filepath));

return $response;