Skip to content

Commit

Permalink
Merge pull request #15 from sitegeist/task/addErrorImage
Browse files Browse the repository at this point in the history
FEATURE: Add error image that is rendered when a driver does not support drawing or the given format
  • Loading branch information
mficzel committed Sep 12, 2019
2 parents f2279a6 + 25f3d6f commit 03aade5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 31 deletions.
69 changes: 38 additions & 31 deletions Classes/Controller/DummyImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

/**
Expand Down
Binary file added Resources/Public/Images/imageError.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 03aade5

Please sign in to comment.