diff --git a/Admin/Install/Media/layout01.php b/Admin/Install/Media/layout01.php index 8ae5a25..fc947cd 100644 --- a/Admin/Install/Media/layout01.php +++ b/Admin/Install/Media/layout01.php @@ -11,6 +11,8 @@ $margin = 50; $l = new Label(); +/** @var \Modules\ItemManagement\Models\Item $item */ + // top $text = new Text(); $text->text = $item->getL11n('name1')->content; diff --git a/Admin/Installer.php b/Admin/Installer.php index 3e051b9..3c46681 100644 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -47,13 +47,13 @@ final class Installer extends InstallerAbstract { parent::install($app, $info, $cfgHandler); - /* Bill types */ + /* Label layouts */ $fileContent = \file_get_contents(__DIR__ . '/Install/layouts.json'); if ($fileContent === false) { return; } - /** @var array $types */ + /** @var array $layouts */ $layouts = \json_decode($fileContent, true); if ($layouts === false) { return; diff --git a/Controller/BackendController.php b/Controller/BackendController.php index e836563..ca8bc3b 100644 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -49,7 +49,7 @@ final class BackendController extends Controller $view->setTemplate('/Modules/Labeling/Theme/Backend/layout-list'); $view->data['nav'] = $this->app->moduleManager->get('Navigation')->createNavigationMid(1005701001, $request, $response); - /** @var \Modules\Attribute\Models\AttributeType[] $attributes */ + /** @var \Modules\Labeling\Models\LabelLayout[] $layouts */ $layouts = LabelLayoutMapper::getAll() ->with('l11n') ->with('template') @@ -125,15 +125,16 @@ final class BackendController extends Controller $view->data['item'] = $item; - /** @var \Modules\Attribute\Models\AttributeType[] $attributes */ - $layouts = LabelLayoutMapper::getAll() + /** @var \Modules\Labeling\Models\LabelLayout[] $layout */ + $layout = LabelLayoutMapper::get() ->with('l11n') ->with('template') ->with('template/sources') ->where('l11n/language', $response->header->l11n->language) + ->where('id', (int) $request->getData('id')) ->execute(); - $view->data['layouts'] = $layouts; + $view->data['layout'] = $layout; return $view; } diff --git a/Models/Image.php b/Models/Image.php index 9fae126..775cfca 100644 --- a/Models/Image.php +++ b/Models/Image.php @@ -28,7 +28,7 @@ class Image public string $src = ''; - public $resource = null; + public ?\GdImage $resource = null; public int $color = 0; } diff --git a/Models/Label.php b/Models/Label.php index b3ae934..1a533e4 100644 --- a/Models/Label.php +++ b/Models/Label.php @@ -26,10 +26,18 @@ class Label public array $elements = []; - public function render() + public function render() : ?\GdImage { $im = \imagecreatetruecolor((int) (37.8 * $this->width), (int) (37.8 * $this->height)); + if ($im === false) { + return null; + } + $bg = \imagecolorallocatealpha($im, 255, 255, 255, 0); + if ($bg === false) { + return null; + } + \imagefill($im, 0, 0, $bg); /* @@ -79,6 +87,9 @@ class Label \imagettftext($im, $element->size, 0, $element->x, $element->y, $color, $element->font, $element->text); } elseif ($element instanceof Image) { $in = $element->resource === null ? \imagecreatefrompng(__DIR__ . '/../../..' . $element->src) : $element->resource; + if ($in === false) { + return null; + } $srcW = \imagesx($in); $srcH = \imagesy($in); @@ -95,6 +106,10 @@ class Label $newH = (int) ($srcH * $ratio); $newIn = \imagecreatetruecolor($newW, $newH); + if ($newIn === false) { + return null; + } + \imagecolortransparent($newIn, \imagecolorallocatealpha($newIn, 0, 0, 0, 127)); \imagealphablending($newIn, false); \imagesavealpha($newIn, true);