objement / imagick-canvas
Library to easily generate Imagick graphics containing pictures, texts and shapes.
v0.1.2
2022-11-01 23:27 UTC
Requires
- php: >=7.4
- ext-imagick: *
Requires (Dev)
- phpunit/phpunit: ^9
README
PHP-Library to easily generate Imagick graphics containing pictures, texts and shapes by writing object-oriented PHP code.
Installation
The library is available on Packagist and can therefore be installed using Composer.
composer require objement/imagick-canvas
Examples
Create a centered watermark image
$image = new OmElementImage($filepath); $canvas = new OmCanvas( OmCanvas::RESOLUTION_DEFAULT_SCREEN, // for web (resolution is important when working with texts) OmCanvas::COLORSPACE_RGB, // for web RGB, use CMYK for print $image->getWidth(), $image->getHeight() ); $canvas->addElement($image, OmElementPosition::create(OmUnit::UNIT_PIXELS, 0, 0)); $watermark = new OmElementImage(realpath('watermark.png'), $image->getWidth()->divide(5)); $canvas->addElement($watermark, OmElementPosition::create(OmUnit::UNIT_PIXELS, $image->getWidth()->divide(2)->subtract($watermark->getWidth()->divide(2)->getValue())->getValue(), // center it: (image width / 2) - (watermark width / 2) $image->getHeight()->divide(2)->subtract($watermark->getHeight()->divide(2)->getValue())->getValue() )); $canvas->getImage('png')->writeImage($filepath);