Example

Example – Usage example for Image_Canvas

Example

Generation of a sample image in PNG format

<?php
require_once 'Image/Canvas.php';

// change the output format with the first parameter of factory()
$Canvas =& Image_Canvas::factory('png', array('width' => 400'height' => 300));

$Canvas->setLineColor('black');
$Canvas->rectangle(array('x0' => 0'y0' => 0'x1' => 399'y1' => 299));

$Canvas->setGradientFill(array('direction' => 'horizontal''start' => 'red''end' => 'blue'));
$Canvas->setLineColor('black');
$Canvas->ellipse(array('x' => 199'y' => 149'rx' => 50'ry' => 50));

$Canvas->setFont(array('name' => 'Arial''size' => 12));
$Canvas->addText(array('x' => 0'y' => 0'text' => 'Demonstration of what Image_Canvas do!'));

$Canvas->setFont(array('name' => 'Times New Roman''size' => 12));
$Canvas->addText(array('x' => 399'y' => 20'text' => 'This does not demonstrate what is does!''alignment' => array('horizontal' => 'right')));

$Canvas->setFont(array('name' => 'Courier New''size' => 7'angle' => 270));
$Canvas->addText(array('x' => 350'y' => 50'text' => 'True, but it\'s all independent of the format!''alignment' => array('horizontal' => 'right')));

$Canvas->setFont(array('name' => 'Garamond''size' => 10));
$Canvas->addText(array('x' => 199'y' => 295'text' => '[Changing format is done by changing 3 letters in the source]''alignment' => array('horizontal' => 'center''vertical' => 'bottom')));

$Canvas->addVertex(array('x' => 50'y' => 200));
$Canvas->addVertex(array('x' => 100'y' => 200));
$Canvas->addVertex(array('x' => 100'y' => 250));
$Canvas->setFillColor('red@0.2');
$Canvas->polygon(array('connect' => true));

$Canvas->image(array('x' => 398'y' => 298'filename' => './pear-icon.png''alignment' => array('horizontal' => 'right''vertical' => 'bottom')));

$Canvas->show();
?>
Image_Canvas (Previous) Image_Graph (Next)
Last updated: Thu, 30 Oct 2014 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report or add a note.
View this page in:

User Notes:

There are no user contributed notes for this page.