Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use GifBuilder for Placeholder images instead of relying on 3rd party #119

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion Classes/Domain/Model/PlaceholderImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace SMS\FluidComponents\Domain\Model;

use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
use TYPO3\CMS\Frontend\Imaging\GifBuilder;

/**
* Data structure for a placeholder image to be passed to a component
*/
Expand Down Expand Up @@ -52,6 +56,31 @@ public function getHeight(): int

public function getPublicUrl(): string
{
return 'https://via.placeholder.com/' . $this->width . 'x' . $this->height;
$gifBuilder = GeneralUtility::makeInstance(GifBuilder::class);
$gifBuilder->start(
[
'XY' => implode(',', [$this->width, $this->height]),
'backColor' => '#C0C0C0',
'format' => 'jpg',
'10' => 'TEXT',
'10.' => [
'text' => implode('x', [$this->width, $this->height]),
'fontColor' => '#000000',
'fontSize' => 26,
'antiAlias' => false,
'align' => 'center',
'offset' => implode(',', [0,$this->height / 2]),
],
Comment on lines +62 to +73
Copy link
Author

@sascha-egerer sascha-egerer Jan 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a rough implementation... I would be very happy to discuss ideas on how we can improve this.

],
[]
);

$prefix = '/';

if(($GLOBALS['TSFE'] ?? null) instanceof TypoScriptFrontendController && $GLOBALS['TSFE']->absRefPrefix !== '') {
$prefix = $GLOBALS['TSFE']->absRefPrefix;
}

return $prefix . $gifBuilder->gifBuild();
}
}