Skip to content

Example: filament spool inventory label

A small inventory label for a 3D printer filament spool: a header with the brand/material and a spool number, a QR code for scanning, and a key/value block of print settings next to a short free-text note.

Example output image

<?php
require 'vendor/autoload.php';
use Kehet\ImagickLayoutEngine\Containers\ColumnContainer;
use Kehet\ImagickLayoutEngine\Containers\RowContainer;
use Kehet\ImagickLayoutEngine\Enums\Gravity;
use Kehet\ImagickLayoutEngine\Enums\ImageMode;
use Kehet\ImagickLayoutEngine\Items\Image;
use Kehet\ImagickLayoutEngine\Items\Text;
use Kehet\ImagickLayoutEngine\Items\TextWrap;
$width = 500;
$height = 360;
$imagick = new Imagick;
$imagick->newImage($width, $height, new ImagickPixel('white'));
$root = new ColumnContainer();
$root->setGap(10);
$root->setMargin(10);
$header = new RowContainer();
$header->setGap(20);
$draw = draw(fill: 'black');
$draw->setFont('DejaVu-Sans-Bold');
$header->addItem(
new Text(
$draw,
"Acme Filaments Ltd.\nOrange no. 5 - PLA"
)
);
$header->addItem(
new Text(
$draw,
"#3",
gravity: Gravity::CENTER
),
forceSize: 75
);
$root->addItem($header, 100);
$body = new RowContainer();
$body->setGap(10);
// Left side
$body->addItem(
new Image(
'example-qr.png',
ImageMode::FILL
)
);
// Right side
$rightSide = new ColumnContainer();
$rightSide->setGap(20);
$draw->setFont('DejaVu-Sans');
$keyValueColumn = new RowContainer();
$keyValueColumn->setGap(10);
$keyValueColumn->addItem(
new Text(
$draw,
"Spool\nNozzle\nHeatbed\nDiameter\nLot Nr",
minFontSize: 20
)
);
$keyValueColumn->addItem(
new Text(
$draw,
"193g\n215 °C\n50-60 °C\n1,75 mm\n3",
minFontSize: 20
)
);
$rightSide->addItem($keyValueColumn);
$rightSide->addItem(
new TextWrap(
$draw,
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
initialFontSize: 20
)
);
$body->addItem($rightSide);
$root->addItem($body);
$root->draw($imagick, 0, 0, $width, $height);
$imagick->setImageFormat('png');
$imagick->writeImage(__DIR__ . '/55-filament-spool-label.png');

The key/value pair uses two Text items in a RowContainer with minFontSize so the settings shrink together rather than each column scaling independently, and the QR code reuses the same placeholder image as the QR code guide.

The same layout as a template. One quirk from the PHP carries over here: the header is built with $draw->setFont('DejaVu-Sans-Bold'), but that ImagickDraw is the same object (by reference) reused for the key/value text below it, and the later $draw->setFont('DejaVu-Sans') call mutates it before anything actually draws — so the header renders in the regular weight too, same as the published output. Every node below gets its own independent ImagickDraw, so the header is written with "font": "DejaVu-Sans" to match:

{
"type": "column",
"gap": 10,
"margin": 10,
"children": [
{
"type": "row",
"gap": 20,
"size": 100,
"children": [
{"type":"text","text":"Acme Filaments Ltd.\nOrange no. 5 - PLA","fill":"black","font":"DejaVu-Sans"},
{"type":"text","text":"#3","fill":"black","font":"DejaVu-Sans","gravity":"center","size":75}
]
},
{
"type": "row",
"gap": 10,
"children": [
{"type":"image","file":"example-qr.png","mode":"fill"},
{
"type": "column",
"gap": 20,
"children": [
{
"type": "row",
"gap": 10,
"children": [
{"type":"text","text":"Spool\nNozzle\nHeatbed\nDiameter\nLot Nr","fill":"black","font":"DejaVu-Sans","minFontSize":20},
{"type":"text","text":"193g\n215 °C\n50-60 °C\n1,75 mm\n3","fill":"black","font":"DejaVu-Sans","minFontSize":20}
]
},
{"type":"text-wrap","text":"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.","fill":"black","font":"DejaVu-Sans","fontSize":20}
]
}
]
}
]
}

llms.txt