public function resizeAction($imageName)
    {
        try {
            $imageOptimizer = $this->get('harentius_blog.image_optimizer');
            $imagePath = $imageOptimizer->createPreviewIfNotExists($imageName);

            return new BinaryFileResponse($imagePath);
        } catch (\Exception $e) {
            throw new NotFoundHttpException(sprintf('File %s not found', $imageName));
        }
    }
public function resizeAction($imageName)
    {
        try {
            $imageOptimizer = $this->get('harentius_blog.image_optimizer');
            $imagePath = $imageOptimizer->createPreviewIfNotExists($imageName);

            return new BinaryFileResponse($imagePath);
        } catch (\Exception $e) {
            throw new NotFoundHttpException(sprintf('File %s not found', $imageName));
        }
    }
public function resizeAction ( $ imageName ) { try { $ imageOptimizer = $ this -> get ( 'harentius_blog.image_optimizer' ) ; $ imagePath = $ imageOptimizer -> createPreviewIfNotExists ( $ imageName ) ; return new BinaryFileResponse ( $ imagePath ) ; } catch ( \ Exception $ e ) { throw new NotFoundHttpException ( sprintf ( 'File %s not found' , $ imageName ) ) ; } }
For optimization, try_files should be set in nginx
Then BinaryFileResponse only once, when crete cache preview.

@param string $imageName
@return Response
For optimization try_files should be set in nginx Then BinaryFileResponse only once when crete cache preview .