class_BaseImage.php

Go to the documentation of this file.
00001 <?php
00024 class BaseImage extends BaseFrameworkSystem implements Registerable {
00028         private $imageType = "";
00029 
00033         private $width = "";
00034 
00038         private $height = "";
00039 
00043         private $backgroundColor = array(
00044                 'red'   => "",
00045                 'green' => "",
00046                 'blue'  => ""
00047         );
00048 
00052         private $foregroundColor = array(
00053                 'red'   => "",
00054                 'green' => "",
00055                 'blue'  => ""
00056         );
00057 
00061         private $colorMode = "";
00062 
00066         private $imageResource = null;
00067 
00071         private $imageName = "";
00072 
00076         private $stringName = "";
00077 
00081         private $groupable = "single";
00082 
00089         protected function __construct ($className) {
00090                 // Call parent constructor
00091                 parent::__construct($className);
00092 
00093                 // Clean up a little
00094                 $this->removeNumberFormaters();
00095                 $this->removeSystemArray();
00096         }
00097 
00105         private final function setColor ($colorMode, $colorChannel, $colorValue) {
00106                 // Construct the eval() command
00107                 $eval = sprintf("\$this->%s['%s'] = \"%s\";",
00108                         $colorMode,
00109                         $colorChannel,
00110                         $colorValue
00111                 );
00112 
00113                 // Run the command
00114                 //* DEBUG: */ echo "mode={$colorMode}, channel={$colorChannel}, value={$colorValue}<br />\n";
00115                 eval($eval);
00116         }
00117 
00124         public final function setWidth ($width) {
00125                 $this->width = $width;
00126         }
00127 
00133         public final function getWidth () {
00134                 return $this->width;
00135         }
00136 
00143         public final function setHeight ($height) {
00144                 $this->height = $height;
00145         }
00146 
00152         public final function getHeight () {
00153                 return $this->height;
00154         }
00155 
00162         public function finishType () {
00163                 // Empty at the momemt
00164         }
00165 
00172         public function initResolution () {
00173                 // Empty at the momemt
00174         }
00175 
00182         public function finishResolution () {
00183                 // Empty at the momemt
00184         }
00185 
00192         public function initBase () {
00193                 // Empty at the momemt
00194         }
00195 
00202         public function finishBase () {
00203                 // Empty at the momemt
00204         }
00205 
00211         public function initBackgroundColor () {
00212                 $this->colorMode = "backgroundColor";
00213         }
00214 
00221         public function finishBackgroundColor () {
00222                 // Empty at the moment
00223         }
00224 
00230         public function initForegroundColor () {
00231                 $this->colorMode = "foregroundColor";
00232         }
00233 
00240         public function finishForegroundColor () {
00241                 // Empty at the moment
00242         }
00243 
00251         public function initImageString ($groupable = "single") {
00252                 $this->groupable = $groupable;
00253         }
00254 
00261         public function finishImageString () {
00262                 // Empty at the momemt
00263         }
00264 
00271         public final function setRed ($red) {
00272                 // Get array name
00273                 $arrayName = $this->colorMode;
00274 
00275                 // Set image color
00276                 $this->setColor($arrayName, 'red', $red);
00277         }
00278 
00285         public final function setGreen ($green) {
00286                 // Get array name
00287                 $arrayName = $this->colorMode;
00288 
00289                 // Set image color
00290                 $this->setColor($arrayName, 'green', $green);
00291         }
00292 
00299         public final function setBlue ($blue) {
00300                 // Get array name
00301                 $arrayName = $this->colorMode;
00302 
00303                 // Set image color
00304                 $this->setColor($arrayName, 'blue', $blue);
00305         }
00306 
00313         public final function setString ($string) {
00314                 $this->imageString = (string) $string;
00315         }
00316 
00322         public final function getString () {
00323                 return $this->imageString;
00324         }
00325 
00332         protected final function setImageType ($imageType) {
00333                 $this->imageType = (string) $imageType;
00334         }
00335 
00341         public final function getImageType () {
00342                 return $this->imageType;
00343         }
00344 
00351         public final function setImageName ($name) {
00352                 $this->imageName = (string) $name;
00353         }
00354 
00360         public final function getImageName () {
00361                 return $this->imageName;
00362         }
00363 
00369         public final function getImageResource() {
00370                 return $this->imageResource;
00371         }
00372 
00379         public final function setX ($x) {
00380                 $this->x = $x;
00381         }
00382 
00388         public final function getX () {
00389                 return $this->x;
00390         }
00391 
00398         public final function setY ($y) {
00399                 $this->y = $y;
00400         }
00401 
00407         public final function getY () {
00408                 return $this->y;
00409         }
00410 
00417         public final function setFontSize ($fontSize) {
00418                 $this->fontSize = $fontSize;
00419         }
00420 
00426         public final function getFontSize () {
00427                 return $this->fontSize;
00428         }
00429 
00436         public final function setStringName($stringName) {
00437                 $this->stringName = $stringName;
00438         }
00439 
00445         public function finishImage () {
00446                 // Get template instance
00447                 $templateInstance = $this->getTemplateInstance();
00448 
00449                 // Compile width and height
00450                 $width = $templateInstance->compileRawCode($this->getWidth());
00451                 $height = $templateInstance->compileRawCode($this->getHeight());
00452 
00453                 // Set both again
00454                 $this->setWidth($width);
00455                 $this->setHeight($height);
00456 
00457                 // Get a image resource
00458                 $this->imageResource = imagecreatetruecolor($width, $height);
00459 
00460                 // Compile background colors
00461                 $red   = $templateInstance->compileRawCode($this->backgroundColor['red']);
00462                 $green = $templateInstance->compileRawCode($this->backgroundColor['green']);
00463                 $blue  = $templateInstance->compileRawCode($this->backgroundColor['blue']);
00464 
00465                 // Set all back
00466                 $this->initBackgroundColor();
00467                 $this->setRed($red);
00468                 $this->setGreen($green);
00469                 $this->setBlue($blue);
00470 
00471                 // Get a pointer for background color
00472                 $backColor = imagecolorallocate($this->getImageResource(), $red, $green, $blue);
00473 
00474                 // Fill the image
00475                 imagefill($this->getImageResource(), 0, 0, $backColor);
00476 
00477                 // Compile foreground colors
00478                 $red   = $templateInstance->compileRawCode($this->foregroundColor['red']);
00479                 $green = $templateInstance->compileRawCode($this->foregroundColor['green']);
00480                 $blue  = $templateInstance->compileRawCode($this->foregroundColor['blue']);
00481 
00482                 // Set all fore
00483                 $this->initForegroundColor();
00484                 $this->setRed($red);
00485                 $this->setGreen($green);
00486                 $this->setBlue($blue);
00487 
00488                 // Get a pointer for foreground color
00489                 $foreColor = imagecolorallocate($this->getImageResource(), $red, $green, $blue);
00490 
00491                 switch ($this->groupable) {
00492                         case "single": // Single image string
00493                                 // Compile image string
00494                                 $imageString = $templateInstance->compileRawCode($this->getString());
00495 
00496                                 // Set it back
00497                                 $this->setString($imageString);
00498 
00499                                 // Compile X/Y coordinates and font size
00500                                 $x    = $templateInstance->compileRawCode($this->getX());
00501                                 $y    = $templateInstance->compileRawCode($this->getY());
00502                                 $size = $templateInstance->compileRawCode($this->getFontSize());
00503 
00504                                 // Set the image string
00505                                 imagestring($this->getImageResource(), $size, $x, $y, $imageString, $foreColor);
00506                                 break;
00507 
00508                         case "groupable": // More than one string allowed
00509                                 // Walk through all groups
00510                                 foreach ($templateInstance->getVariableGroups() as $group => $set) {
00511                                         // Set the group
00512                                         $templateInstance->setVariableGroup($group, false);
00513 
00514                                         // Compile image string
00515                                         $imageString = $templateInstance->compileRawCode($this->getString());
00516 
00517                                         // Compile X/Y coordinates and font size
00518                                         $x    = $templateInstance->compileRawCode($this->getX());
00519                                         $y    = $templateInstance->compileRawCode($this->getY());
00520                                         $size = $templateInstance->compileRawCode($this->getFontSize());
00521 
00522                                         // Set the image string
00523                                         //* DEBUG: */ echo __METHOD__.": size={$size}, x={$x}, y={$y}, string={$imageString}<br />\n";
00524                                         imagestring($this->getImageResource(), $size, $x, $y, $imageString, $foreColor);
00525                                 } // END - foreach
00526                                 break;
00527                 }
00528 
00529                 // You need finishing in your image class!
00530         }
00531 
00537         public function getContent () {
00538                 // Get cache file name
00539                 $cacheFile = $this->getTemplateInstance()->getImageCacheFqfn();
00540 
00541                 // Load the content
00542                 $imageContent = file_get_contents($cacheFile);
00543 
00544                 // And return it
00545                 return $imageContent;
00546         }
00547 }
00548 // [EOF]
00549 ?>

Generated on Mon Dec 8 01:06:46 2008 for Ship-Simulator by  doxygen 1.5.6