1<?php
2
3/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5/**
6 * Image_Graph - PEAR PHP OO Graph Rendering Utility.
7 *
8 * PHP version 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_Graph
23 * @subpackage Fill
24 * @author     Jesper Veggerby <pear.nosey@veggerby.dk>
25 * @author     Stefan Neufeind <pear.neufeind@speedpartner.de>
26 * @copyright  2003-2009 The PHP Group
27 * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
28 * @version    SVN: $Id: Gradient.php 291170 2009-11-23 03:50:22Z neufeind $
29 * @link       http://pear.php.net/package/Image_Graph
30 */
31
32/**
33 * Include file Image/Graph/Fill/Image.php
34 */
35require_once 'Image/Graph/Fill/Image.php';
36
37/**
38 * Fill using a gradient color.
39 * This creates a scaled fillstyle with colors flowing gradiently between 2
40 * specified RGB values. Several directions are supported:
41 *
42 * 1 Vertically (IMAGE_GRAPH_GRAD_VERTICAL)
43 *
44 * 2 Horizontally (IMAGE_GRAPH_GRAD_HORIZONTAL)
45 *
46 * 3 Mirrored vertically (the color grades from a- b-a vertically)
47 * (IMAGE_GRAPH_GRAD_VERTICAL_MIRRORED)
48 *
49 * 4 Mirrored horizontally (the color grades from a-b-a horizontally)
50 * IMAGE_GRAPH_GRAD_HORIZONTAL_MIRRORED
51 *
52 * 5 Diagonally from top-left to right-bottom
53 * (IMAGE_GRAPH_GRAD_DIAGONALLY_TL_BR)
54 *
55 * 6 Diagonally from bottom-left to top-right
56 * (IMAGE_GRAPH_GRAD_DIAGONALLY_BL_TR)
57 *
58 * 7 Radially (concentric circles in the center) (IMAGE_GRAPH_GRAD_RADIAL)
59 *
60 * @category   Images
61 * @package    Image_Graph
62 * @subpackage Fill
63 * @author     Jesper Veggerby <pear.nosey@veggerby.dk>
64 * @author     Stefan Neufeind <pear.neufeind@speedpartner.de>
65 * @copyright  2003-2009 The PHP Group
66 * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
67 * @version    Release: 0.8.0
68 * @link       http://pear.php.net/package/Image_Graph
69 */
70class Image_Graph_Fill_Gradient extends Image_Graph_Fill //Image_Graph_Fill_Image
71{
72
73    /**
74     * The direction of the gradient
75     * @var int
76     * @access private
77     */
78    var $_direction;
79
80    /**
81     * The first color to gradient
82     * @var mixed
83     * @access private
84     */
85    var $_startColor;
86
87    /**
88     * The last color to gradient
89     * @var mixed
90     * @access private
91     */
92    var $_endColor;
93
94    /**
95     * Image_Graph_GradientFill [Constructor]
96     *
97     * @param int   $direction  The direction of the gradient
98     * @param mixed $startColor The value of the starting color
99     * @param mixed $endColor   The value of the ending color
100     */
101    function Image_Graph_Fill_Gradient($direction, $startColor, $endColor)
102    {
103        parent::__construct();
104        $this->_direction = $direction;
105        $this->_startColor = $startColor;
106        $this->_endColor = $endColor;
107    }
108
109    /**
110     * Return the fillstyle
111     *
112     * @param ??? $ID ???
113     *
114     * @return int A GD fillstyle
115     * @access private
116     */
117    function _getFillStyle($ID = false)
118    {
119        switch ($this->_direction) {
120            case IMAGE_GRAPH_GRAD_HORIZONTAL:
121                $direction = 'horizontal';
122                break;
123            case IMAGE_GRAPH_GRAD_VERTICAL:
124                $direction = 'vertical';
125                break;
126            case IMAGE_GRAPH_GRAD_HORIZONTAL_MIRRORED:
127                $direction = 'horizontal_mirror';
128                break;
129            case IMAGE_GRAPH_GRAD_VERTICAL_MIRRORED:
130                $direction = 'vertical_mirror';
131                break;
132            case IMAGE_GRAPH_GRAD_DIAGONALLY_TL_BR:
133                $direction = 'diagonal_tl_br';
134                break;
135            case IMAGE_GRAPH_GRAD_DIAGONALLY_BL_TR:
136                $direction = 'diagonal_bl_tr';
137                break;
138            case IMAGE_GRAPH_GRAD_RADIAL:
139                $direction = 'radial';
140                break;
141        }
142
143        return array(
144            'type' => 'gradient',
145            'start' => $this->_startColor,
146            'end' => $this->_endColor,
147            'direction' => $direction
148        );
149    }
150
151}
152
153?>
154