PHP Classes
elePHPant
Icontem

File: docs/classes/canvas.md

Recommend this page to a friend!
  Classes of Jose Luis Quintana  >  GImage  >  docs/classes/canvas.md  >  Download  
File: docs/classes/canvas.md
Role: Example script
Content type: text/markdown
Description: Example script
Class: GImage
Create graphic images with a fluent interface
Author: By
Last change:
Date: 5 months ago
Size: 997 bytes
 

Contents

Class file image Download

Canvas

> Canvas represents an area on which it can append images, text and figures.

!!! tip "Note"

__Canvas__ needs a `Figure` or `Image` which will be used as base element (layout).

The following example uses append() method to attach elements to canvas.

!!! tip "Tip"

Using  `setLeft()` or `setTop()` methods it can control the position (x,y) of the elements (`Figure`, `Image` or `Text`) on canvas.

<?php

use GImage\Image;
use GImage\Figure;
use GImage\Canvas;

$image = new Image();
$image
    ->load('https://my_website.com/images/my_image.png')

$ellipse = new Figure(200, 200);
$ellipse
    ->isEllipse()
    ->setBackgroundColor(200, 0, 0)
    ->setTop(60)
    ->setLeft(70)
    ->create()

// Used as layout
$layout = new Figure(200, 200);
$layout
    ->setBackgroundColor(0, 0, 255)
    ->create()

$canvas = new Canvas($layout);
$canvas
    ->append([$image, $ellipse])
    ->toPNG()
    ->draw()
    ->save('/home/my_user/images/my_composed_image.png');