When sending an image/file from a Symfony controller you would usually read the file from filesystem.
This you can do by passing the file path to the BinaryFileResponse class and return it in the controller, as described in the docs:
https://symfony.com/doc/current/components/http_foundation.html#serving-files
use Symfony\Component\HttpFoundation\BinaryFileResponse;
$file = 'path/to/file.txt';
$response = new BinaryFileResponse($file);
Code language: PHP (php)
But in some cases you might want to create an image dynamically and return it directly from the controller without storing it on the filesystem.
So you can create your image with the GD library and directly stream the GDImage object from the symfony controller with the StreamedResponse class.