Skip to content

StackContainer

StackContainer draws its children on top of each other within the same content area. This can be used eg. to draw text over an image.

$container = new StackContainer;
$container->addItem(new Image('example-image-large.jpeg', ImageMode::FILL));
$container->addItem(new Text(draw(fill: '#fff'), 'Text over image', initialFontSize: 150, gravity: Gravity::CENTER));
// Draw container onto image
$container->draw($imagick, $x, $y, $width, $height);

White centered text drawn on top of a background image

The same layout as a template:

{
"type": "stack",
"children": [
{ "type": "image", "file": "example-image-large.jpeg", "mode": "fill" },
{ "type": "text", "text": "Text over image", "fill": "#fff", "fontSize": 150, "gravity": "center" }
]
}

llms.txt