From 25f3d6f020076e0e36b1faaa8d675014cc002054 Mon Sep 17 00:00:00 2001 From: Martin Ficzel Date: Thu, 12 Sep 2019 12:13:26 +0200 Subject: [PATCH] FEATURE: Add error image that is rendered when a driver does not support drawing or the given format The red-png dummyImage is returned with statusCode 500 to make it easy to spot in the rendering but also in the network tab. --- Classes/Controller/DummyImageController.php | 69 +++++++++++--------- Resources/Public/Images/imageError.png | Bin 0 -> 10601 bytes 2 files changed, 38 insertions(+), 31 deletions(-) create mode 100644 Resources/Public/Images/imageError.png diff --git a/Classes/Controller/DummyImageController.php b/Classes/Controller/DummyImageController.php index 2bda532..d338063 100644 --- a/Classes/Controller/DummyImageController.php +++ b/Classes/Controller/DummyImageController.php @@ -71,48 +71,55 @@ public function imageAction (int $w = 600, int $h = 400, string $bg = '#000', st $height = $h; $text = $t; - // create imagine - $palette = new Palette\RGB(); - $backgroundColor = $palette->color($bg); - $foregroundColor = $palette->color($fg); + try { + // create imagine + $palette = new Palette\RGB(); + $backgroundColor = $palette->color($bg); + $foregroundColor = $palette->color($fg); - // create image - $imageBox = new Box($width, $height); - $image = $this->imagineService->create($imageBox); - $image->usePalette($palette); + // create image + $imageBox = new Box($width, $height); + $image = $this->imagineService->create($imageBox); + $image->usePalette($palette); - // render border - $renderBorder = ($w >= 70 && $h >= 70); + // render border + $renderBorder = ($width >= 70 && $height >= 70); - // render shape - $renderShape = ($w >= 200 && $h >= 100); + // render shape + $renderShape = ($width >= 200 && $height >= 100); - $renderText = ($w >= 50 && $h >= 30); + $renderText = ($width >= 50 && $height >= 30); - $renderPattern = ($w >= 20 && $h >= 20); + $renderPattern = ($width >= 20 && $height >= 20); - $this->renderBackground($image, $foregroundColor, $backgroundColor, $width, $height); + $this->renderBackground($image, $foregroundColor, $backgroundColor, $width, $height); - if ($renderShape) { - $this->renderShape($image, $foregroundColor, $backgroundColor, $width, $height); - } + if ($renderShape) { + $this->renderShape($image, $foregroundColor, $backgroundColor, $width, $height); + } - if ($renderBorder) { - $this->renderBorder($image, $foregroundColor, $backgroundColor, $width, $height); - } + if ($renderBorder) { + $this->renderBorder($image, $foregroundColor, $backgroundColor, $width, $height); + } - if ($t && $renderText) { - $this->renderText($image, $foregroundColor, $width, $height, $text, $renderShape ? false : true); - } + if ($t && $renderText) { + $this->renderText($image, $foregroundColor, $width, $height, $text, $renderShape ? false : true); + } - if ($renderPattern) { - $this->renderPattern($image, $renderShape ? $backgroundColor : $foregroundColor, $width, $height, $text); - } + if ($renderPattern) { + $this->renderPattern($image, $renderShape ? $backgroundColor : $foregroundColor, $width, $height, $text); + } - // build result - $this->response->setHeader( 'Cache-Control', 'max-age=883000000'); - $this->response->setHeader( 'Content-type', 'image/' . $f); - return $image->get($f); + // build result + $this->response->setHeader('Cache-Control', 'max-age=883000000'); + $this->response->setHeader('Content-type', 'image/' . $f); + return $image->get($f); + } catch (\Exception $e) { + // something went wrong we return the error image png + $this->response->setStatusCode(500); + $this->response->setHeader('Content-type', 'image/png'); + return file_get_contents('resource://Sitegeist.Kaleidoscope/Public/Images/imageError.png'); + } } /** diff --git a/Resources/Public/Images/imageError.png b/Resources/Public/Images/imageError.png new file mode 100644 index 0000000000000000000000000000000000000000..ba897f914d48519387d3ca931af03f3480dad47b GIT binary patch literal 10601 zcmeHtX*ksH|L&OC-sZUVw&RFj3b0ToP6{0d`nLG zJLZ!bQ$jiyfG1dnAkolyOEu2tp`yavgdUau+|kRT>P2 zhVPX;8da0<<+Tp+g&*tNMwVc)Ta(fFu&jCT{N}ZoT_vK)I?7aVB0DGp#ws|SAiz|z3{yP z7%*SZ17Y>~w)UW}Z{#}wd#T&EQ(!o%__MzfZ=TU4ylE1B=Hm_slA7aRNA73;0%2IU z(xj0FyRShp z=s!wsC&NI}cp6UtFO8z^Iv@Z`+oS)8rTtaH@t6O7ddy!XmlA3G9WsM7f$y)mSOgDw z+5YDGhE^|4Kj)(z+7RLf7y_S1I1s?JD?M;PkPilY`=JE^1tskN6>?7e6jB%JbJ*QM zpv28j_Tx3ht?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