3 * A helper for creating images
5 * @author Roland Haeder <webmaster@ship-simu.org>
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
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.
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.
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/>.
24 class ImageHelper extends BaseHelper implements HelpableTemplate {
28 private $imageType = "png";
31 * Width of the image in pixel
36 * Height of the image in pixel
41 * Array for background color values
43 private $backgroundColor = array(
50 * Array for foreground color values
52 private $foregroundColor = array(
59 * Image message string
61 private $imageString = "No message set!";
64 * Protected constructor
68 protected function __construct () {
69 // Call parent constructor
70 parent::__construct(__CLASS__);
72 // Set part description
73 $this->setObjectDescription("A image helper class");
77 * Creates the helper class
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
83 public final static function createImageHelper (CompileableTemplate $templateInstance, $imageType) {
85 $helperInstance = new ImageHelper();
87 // Set template instance
88 $helperInstance->setTemplateInstance($templateInstance);
90 // Set image type (blindly)
91 $helperInstance->setImageType($imageType);
93 // Return the prepared instance
94 return $helperInstance;
98 * Setter for image type
100 * @param $imageType Type of the image
103 protected final function setImageType ($imageType) {
104 $this->imageType = (string) $imageType;
108 * Getter for image type
110 * @return $imageType Type of the image
112 public final function getImageType () {
113 return $this->imageType;
117 * Setter for image width
119 * @param $width Width of the image
122 public final function setWidth ($width) {
123 $this->width = (int) $width;
127 * Getter for image width
129 * @return $width Width of the image
131 public final function getWidth () {
136 * Setter for image height
138 * @param $height Height of the image
141 public final function setHeight ($height) {
142 $this->height = (int) $height;
146 * Getter for image height
148 * @return $height Height of the image
150 public final function getHeight () {
151 return $this->height;
155 * Setter for RGB of background color
157 * @param $red Color value for red
158 * @param $green Color value for green
159 * @param $blue Color value for blue
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;
169 * Setter for RGB of foreground color
171 * @param $red Color value for red
172 * @param $green Color value for green
173 * @param $blue Color value for blue
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;
183 * Setter for image message string
185 * @param $imageString A message to display in the image
188 public final function setImageString ($imageString) {
189 $this->imageString = (string) $imageString;
193 * Getter for image message string
195 * @return $imageString A message to display in the image
197 public final function getImageString () {
198 return $this->imageString;
202 * Setter for base image
204 * @param $baseImage A base image template
207 public final function setBaseImage ($baseImage) {
208 $this->baseImage = (string) $baseImage;
212 * Getter for base image
214 * @return $baseImage A base image template
216 public final function getBaseImage () {
217 return $this->baseImage;
221 * Flushs the content out
225 public function flushContent () {
226 // Get a template instance
227 $templateInstance = $this->getTemplateInstance();
229 // Get the base image
230 $templateInstance->loadCodeTemplate($this->getBaseImage());
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());
244 // Get the raw content
245 $imageContent = $templateInstance->getRawTemplateData();
247 // Transfer all to the template engine
248 $templateInstance->renderImageContent($imageContent);