PHP code example of objement / imagick-canvas

1. Go to this page and download the library: Download objement/imagick-canvas library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

objement / imagick-canvas example snippets


$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);