Skip to content

Drawing a simple container

Example output image

<?php
require 'vendor/autoload.php';
use Kehet\ImagickLayoutEngine\Containers\RowContainer;
use Kehet\ImagickLayoutEngine\Items\Rectangle;
$width = 1500;
$height = 1000;
// Create new image with a white background
$imagick = new Imagick;
$imagick->newImage($width, $height, new ImagickPixel('white'));
// Define the root container, usually RowContainer or ColumnContainer
$root = new RowContainer;
$root->addItem(new Rectangle(draw(fill: '#fb4934')));
$root->addItem(new Rectangle(draw(fill: '#b8bb26')));
$root->addItem(new Rectangle(draw(fill: '#fabd2f')));
$root->addItem(new Rectangle(draw(fill: '#83a598')));
// Draw container onto image
$root->draw($imagick, 0, 0, $width, $height);
// Output image as png to file
$imagick->setImageFormat('png');
$imagick->writeImage(__DIR__.'/01-simple-container.png');

The same layout as a template:

{
"type": "row",
"children": [
{"type":"rectangle","fill":"#fb4934"},
{"type":"rectangle","fill":"#b8bb26"},
{"type":"rectangle","fill":"#fabd2f"},
{"type":"rectangle","fill":"#83a598"}
]
}

llms.txt