]> git.mxchange.org Git - shipsimu.git/blob - inc/classes/main/helper/images/class_ImageHelper.php
5490a408aa5283ecf94c10a3266c027a2e35a4bb
[shipsimu.git] / inc / classes / main / helper / images / class_ImageHelper.php
1 <?php
2 /**
3  * A helper for creating images
4  *
5  * @author              Roland Haeder <webmaster@ship-simu.org>
6  * @version             0.0.0
7  * @copyright   Copyright(c) 2007, 2008 Roland Haeder, this is free software
8  * @license             GNU GPL 3.0 or any newer version
9  * @link                http://www.ship-simu.org
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <http://www.gnu.org/licenses/>.
23  */
24 class ImageHelper extends BaseHelper implements HelpableTemplate {
25         /**
26          * The image type
27          */
28         private $imageType = "png";
29
30         /**
31          * Width of the image in pixel
32          */
33         private $width = 0;
34
35         /**
36          * Height of the image in pixel
37          */
38         private $height = 0;
39
40         /**
41          * Array for background color values
42          */
43         private $backgroundColor = array(
44                 'red'   => 0,
45                 'green' => 0,
46                 'blue'  => 0
47         );
48
49         /**
50          * Array for foreground color values
51          */
52         private $foregroundColor = array(
53                 'red'   => 0,
54                 'green' => 0,
55                 'blue'  => 0
56         );
57
58         /**
59          * Image message string
60          */
61         private $imageString = "No message set!";
62
63         /**
64          * Protected constructor
65          *
66          * @return      void
67          */
68         protected function __construct () {
69                 // Call parent constructor
70                 parent::__construct(__CLASS__);
71
72                 // Set part description
73                 $this->setObjectDescription("A image helper class");
74         }
75
76         /**
77          * Creates the helper class
78          *
79          * @param       $templateInstance       An instance of a template engine
80          * @param       $imageType                      Type of the image
81          * @return      $helperInstance         A preparedf instance of this class
82          */
83         public final static function createImageHelper (CompileableTemplate $templateInstance, $imageType) {
84                 // Get new instance
85                 $helperInstance = new ImageHelper();
86
87                 // Set template instance
88                 $helperInstance->setTemplateInstance($templateInstance);
89
90                 // Set image type (blindly)
91                 $helperInstance->setImageType($imageType);
92
93                 // Return the prepared instance
94                 return $helperInstance;
95         }
96
97         /**
98          * Setter for image type
99          *
100          * @param       $imageType      Type of the image
101          * @return      void
102          */
103         protected final function setImageType ($imageType) {
104                 $this->imageType = (string) $imageType;
105         }
106
107         /**
108          * Getter for image type
109          *
110          * @return      $imageType      Type of the image
111          */
112         public final function getImageType () {
113                 return $this->imageType;
114         }
115
116         /**
117          * Setter for image width
118          *
119          * @param       $width  Width of the image
120          * @return      void
121          */
122         public final function setWidth ($width) {
123                 $this->width = (int) $width;
124         }
125
126         /**
127          * Getter for image width
128          *
129          * @return      $width  Width of the image
130          */
131         public final function getWidth () {
132                 return $this->width;
133         }
134
135         /**
136          * Setter for image height
137          *
138          * @param       $height         Height of the image
139          * @return      void
140          */
141         public final function setHeight ($height) {
142                 $this->height = (int) $height;
143         }
144
145         /**
146          * Getter for image height
147          *
148          * @return      $height         Height of the image
149          */
150         public final function getHeight () {
151                 return $this->height;
152         }
153
154         /**
155          * Setter for RGB of background color
156          *
157          * @param       $red    Color value for red
158          * @param       $green  Color value for green
159          * @param       $blue   Color value for blue
160          * @return      void
161          */
162         public final function setBackgroundColorRedGreenBlue ($red, $green, $blue) {
163                 $this->backgroundColor['red']   = (int) $red;
164                 $this->backgroundColor['green'] = (int) $green;
165                 $this->backgroundColor['blue']  = (int) $blue;
166         }
167
168         /**
169          * Setter for RGB of foreground color
170          *
171          * @param       $red    Color value for red
172          * @param       $green  Color value for green
173          * @param       $blue   Color value for blue
174          * @return      void
175          */
176         public final function setForegroundColorRedGreenBlue ($red, $green, $blue) {
177                 $this->foregroundColor['red']   = (int) $red;
178                 $this->foregroundColor['green'] = (int) $green;
179                 $this->foregroundColor['blue']  = (int) $blue;
180         }
181
182         /**
183          * Setter for image message string
184          *
185          * @param       $imageString    A message to display in the image
186          * @return      void
187          */
188         public final function setImageString ($imageString) {
189                 $this->imageString = (string) $imageString;
190         }
191
192         /**
193          * Getter for image message string
194          *
195          * @return      $imageString    A message to display in the image
196          */
197         public final function getImageString () {
198                 return $this->imageString;
199         }
200
201         /**
202          * Setter for base image
203          *
204          * @param       $baseImage      A base image template
205          * @return      void
206          */
207         public final function setBaseImage ($baseImage) {
208                 $this->baseImage = (string) $baseImage;
209         }
210
211         /**
212          * Getter for base image
213          *
214          * @return      $baseImage      A base image template
215          */
216         public final function getBaseImage () {
217                 return $this->baseImage;
218         }
219
220         /**
221          * Flushs the content out
222          *
223          * @return      void
224          */
225         public function flushContent () {
226                 // Get a template instance
227                 $templateInstance = $this->getTemplateInstance();
228
229                 // Get the base image
230                 $templateInstance->loadCodeTemplate($this->getBaseImage());
231
232                 // Assign all the image values with the template
233                 $templateInstance->assignVariable("image_type"    , $this->getImageType());
234                 $templateInstance->assignVariable("image_width"   , $this->getWidth());
235                 $templateInstance->assignVariable("image_height"  , $this->getHeight());
236                 $templateInstance->assignVariable("image_bg_red"  , $this->backgroundColor['red']);
237                 $templateInstance->assignVariable("image_bg_green", $this->backgroundColor['green']);
238                 $templateInstance->assignVariable("image_bg_blue" , $this->backgroundColor['blue']);
239                 $templateInstance->assignVariable("image_fg_red"  , $this->foregroundColor['red']);
240                 $templateInstance->assignVariable("image_fg_green", $this->foregroundColor['green']);
241                 $templateInstance->assignVariable("image_fg_blue" , $this->foregroundColor['blue']);
242                 $templateInstance->assignVariable("image_string"  , $this->getImageString());
243
244                 // Get the raw content
245                 $imageContent = $templateInstance->getRawTemplateData();
246
247                 // Transfer all to the template engine
248                 $templateInstance->renderImageContent($imageContent);
249         }
250 }
251
252 // [EOF]
253 ?>