PHP Classes

File: docs/content/examples/

Recommend this page to a friend!
  Classes of Jose Luis Quintana   GImage PHP Canvas to Image   docs/content/examples/   Download  
File: docs/content/examples/
Role: Example script
Content type: text/markdown
Description: Example script
Class: GImage PHP Canvas to Image
Create and compose canvas images from other images
Author: By
Last change:
Date: 8 months ago
Size: 1,114 bytes


Class file image Download

Text embedding

GImage supports text embedding with custom TTF fonts using Text class and Canvas.

!!! tip "Tip"

Use `setAlign(str)`, `setValign(str)` functions for control the aligment, `setLineHeight(n)` for line spaces or `setLeft(x)` and `setTop(y)` for position on canvas.


use GImage\Text;
use GImage\Figure;
use GImage\Canvas;

// figure layout used as canvas
$figure = new Figure(400, 250);
    ->setBackgroundColor(47, 42, 39)

// text definition
$text = new Text('My Text with opacity!');
    // box area size for text
    // aligments
    ->setAlign('center') // "none" by default
    ->setValign('center') // "none" by default
    // line height
    // font size
    // font color
    ->setColor(255, 255, 255)
    // font face


// canvas definition
$canvas = new Canvas($figure);
    // append the text element