1<?php
2
3/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5/**
6 * This is a visual test case, testing canvas support for gradient fillings.
7 *
8 * PHP versions 4 and 5
9 *
10 * LICENSE: This library is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 of the License, or (at your
13 * option) any later version. This library is distributed in the hope that it
14 * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
16 * General Public License for more details. You should have received a copy of
17 * the GNU Lesser General Public License along with this library; if not, write
18 * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 * 02111-1307 USA
20 *
21 * @category   Images
22 * @package    Image_Canvas
23 * @author     Jesper Veggerby <pear.nosey@veggerby.dk>
24 * @copyright  Copyright (C) 2003, 2004 Jesper Veggerby Hansen
25 * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
26 * @version    CVS: $Id: gradients.php 262259 2008-07-08 11:45:42Z steinm $
27 * @link       http://pear.php.net/package/Image_Canvas
28 */
29
30require_once 'Image/Canvas.php';
31
32$canvas =& Image_Canvas::factory(
33    'png',
34    array('width' => 605, 'height' => 350)
35);
36
37$gradient = array(
38    'type' => 'gradient',
39    'start' => 'yellow',
40    'end' => 'maroon'
41);
42
43$directions = array('horizontal', 'vertical', 'horizontal_mirror', 'vertical_mirror', 'diagonal_tl_br', 'diagonal_bl_tr', 'radial');
44
45$space = 10;
46$size = 75;
47
48$canvas->setLineColor('black');
49$canvas->rectangle(array('x0' => 0, 'y0' => 0, 'x1' => $canvas->getWidth() - 1, 'y1' => $canvas->getHeight() - 1));
50
51$i = 0;
52foreach ($directions as $direction) {
53    $gradient['direction'] = $direction;
54
55    $x = $space + ($i * ($size + $space));
56
57    $y = $space;
58    $canvas->setGradientFill($gradient);
59    $canvas->rectangle(array('x0' => $x, 'y0' => $y, 'x1' => $x + $size, 'y1' => $y + $size));
60
61    $y += $size + $space;
62    $canvas->setGradientFill($gradient);
63    $canvas->ellipse(array('x' => $x + $size / 2, 'y' => $y + $size / 2, 'rx' => $size / 2, 'ry' => $size / 2));
64
65    $y += $size + $space;
66    $canvas->setGradientFill($gradient);
67    $canvas->pieslice(array('x' => $x + $size / 2, 'y' => $y + $size / 2, 'rx' => $size / 2, 'ry' => $size / 2, 'v1' => 45, 'v2' => 270));
68
69    $y += $size + $space;
70    $points = array();
71    $points[] = array('x' => $x + $size / 3, 'y' => $y);
72    $points[] = array('x' => $x + $size, 'y' => $y + $size / 2);
73    $points[] = array('x' => $x + $size / 3, 'y' => $y + 3 * $size / 4);
74    $points[] = array('x' => $x + $size / 5, 'y' => $y + $size);
75    $points[] = array('x' => $x, 'y' => $y + $size / 3);
76    $y += $size + $space;
77    $canvas->setGradientFill($gradient);
78    foreach ($points as $point) {
79        $canvas->addVertex($point);
80    }
81    $canvas->polygon(array('connect' => true));
82    $i++;
83}
84
85$canvas->show();
86
87?>
88