partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit 20076aa38fc9732463dd921853e6f0d32ad25df0
parent 4b5e4b40cf2b64419de0067ed0597fc80cf2fda0
Author: Felicitus <felicitus@felicitus.org>
Date:   Fri, 24 Jul 2015 19:12:11 +0200

Return an image with 404 not found response if the file can't be found.

Diffstat:
Msrc/PartKeepr/ImageBundle/Controller/ImageController.php | 9++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/PartKeepr/ImageBundle/Controller/ImageController.php b/src/PartKeepr/ImageBundle/Controller/ImageController.php @@ -2,6 +2,7 @@ namespace PartKeepr\ImageBundle\Controller; use Doctrine\ORM\EntityManager; +use Imagine\Exception\InvalidArgumentException; use Imagine\Gd\Imagine; use Imagine\Image\Box; use Imagine\Image\Point; @@ -57,7 +58,13 @@ abstract class ImageController extends FileController $height = 200; } - $file = $this->fitWithin($image, $width, $height); + try { + $file = $this->fitWithin($image, $width, $height); + } catch (InvalidArgumentException $e) { + $this->get('logger')->error($e->getMessage()); + return new ImageNotFoundResponse($request->get("width"), $request->get("height")); + } + return new Response(file_get_contents($file), 200, array("Content-Type" => "image/png"));