Skip to content

Commit

Permalink
TASK: Adjust to the new ActionResponse API and the altered font path
Browse files Browse the repository at this point in the history
  • Loading branch information
mficzel committed Sep 23, 2019
1 parent 0183215 commit d3911a0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions Classes/Controller/DummyImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Imagine\Image\Palette;
use Imagine\Image\Box;
use Imagine\Image\Point;
use Neos\Flow\Http\Component\SetHeaderComponent;

class DummyImageController extends ActionController
{
Expand Down Expand Up @@ -111,13 +112,13 @@ public function imageAction (int $w = 600, int $h = 400, string $bg = '#000', st
}

// build result
$this->response->setHeader('Cache-Control', 'max-age=883000000');
$this->response->setHeader('Content-type', 'image/' . $f);
$this->response->setComponentParameter(SetHeaderComponent::class, 'Cache-Control', 'max-age=883000000');
$this->response->setComponentParameter(SetHeaderComponent::class, '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');
$this->response->setComponentParameter(SetHeaderComponent::class, 'Content-type', 'image/png');
return file_get_contents('resource://Sitegeist.Kaleidoscope/Public/Images/imageError.png');
}
}
Expand Down Expand Up @@ -245,8 +246,13 @@ protected function renderBorder(ImageInterface $image, ColorInterface $foregroun
protected function renderText(ImageInterface $image, ColorInterface $textColor, int $width, int $height, string $text, $center = false): void
{
$initialFontSize = 10;
$fontFile = $this->packageManager->getPackage('Neos.Neos')->getPackagePath() . "Resources/Public/Fonts/NotoSans/NotoSans-Regular.ttf";
$initialFont = $this->imagineService->font($fontFile, $initialFontSize, $textColor);
if (file_exists('resource://Neos.Neos/Public/Fonts/NotoSans/NotoSans-Regular.ttf')) {
$fontFile = $this->packageManager->getPackage('Neos.Neos')->getPackagePath() . "Resources/Public/Fonts/NotoSans/NotoSans-Regular.ttf";
$initialFont = $this->imagineService->font($fontFile, $initialFontSize, $textColor);
} elseif (file_exists('resource://Neos.Neos/Public/Fonts/NotoSans-Regular.ttf')) {
$fontFile = $this->packageManager->getPackage('Neos.Neos')->getPackagePath() . "Resources/Public/Fonts/NotoSans-Regular.ttf";
$initialFont = $this->imagineService->font($fontFile, $initialFontSize, $textColor);
}

// scale text to fit the image
$initialFontBox = $initialFont->box($text);
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "sitegeist/kaleidoscope",
"license": "GPL-3.0-or-later",
"require": {
"neos/neos": "^4.3 || ^5.0 || dev-master",
"neos/neos": "^5.0 || dev-master",
"neos/fusion-afx": "^1.2 || dev-master",
"neos/media": "*",
"neos/imagine": "*"
Expand Down

0 comments on commit d3911a0

Please sign in to comment.