pImage.class.php

File

inc/pchart/pchart/class/pImage.class.php
View source
  1. /*
  2. pDraw - pChart core class
  3. Version : 2.1.4
  4. Made by : Jean-Damien POGOLOTTI
  5. Last Update : 19/01/2014
  6. This file can be distributed under the license you can find at :
  7. http://www.pchart.net/license
  8. You can find the whole class documentation on the pChart web site.
  9. */
  10. /* The GD extension is mandatory */
  11. if (!extension_loaded('gd') && !extension_loaded('gd2'))
  12. {
  13. echo "GD extension must be loaded. \r\n";
  14. exit();
  15. }
  16. /* Image map handling */
  17. define("IMAGE_MAP_STORAGE_FILE" , 680001);
  18. define("IMAGE_MAP_STORAGE_SESSION" , 680002);
  19. /* Last generated chart layout */
  20. define("CHART_LAST_LAYOUT_REGULAR" , 680011);
  21. define("CHART_LAST_LAYOUT_STACKED" , 680012);
  22. /* ImageMap string delimiter */
  23. define("IMAGE_MAP_DELIMITER" , chr(1));
  24. class pImage extends pDraw
  25. {
  26. /* Image settings, size, quality, .. */
  27. var $XSize = NULL; // Width of the picture
  28. var $YSize = NULL; // Height of the picture
  29. var $Picture = NULL; // GD picture object
  30. var $Antialias = TRUE; // Turn antialias on or off
  31. var $AntialiasQuality = 0; // Quality of the antialiasing implementation (0-1)
  32. var $Mask = ""; // Already drawn pixels mask (Filled circle implementation)
  33. var $TransparentBackground = FALSE; // Just to know if we need to flush the alpha channels when rendering
  34. /* Graph area settings */
  35. var $GraphAreaX1 = NULL; // Graph area X origin
  36. var $GraphAreaY1 = NULL; // Graph area Y origin
  37. var $GraphAreaX2 = NULL; // Graph area bottom right X position
  38. var $GraphAreaY2 = NULL; // Graph area bottom right Y position
  39. /* Scale settings */
  40. var $ScaleMinDivHeight = 20; // Minimum height for scame divs
  41. /* Font properties */
  42. var $FontName = "fonts/GeosansLight.ttf"; // Default font file
  43. var $FontSize = 12; // Default font size
  44. var $FontBox = NULL; // Return the bounding box of the last written string
  45. var $FontColorR = 0; // Default color settings
  46. var $FontColorG = 0; // Default color settings
  47. var $FontColorB = 0; // Default color settings
  48. var $FontColorA = 100; // Default transparency
  49. /* Shadow properties */
  50. var $Shadow = FALSE; // Turn shadows on or off
  51. var $ShadowX = NULL; // X Offset of the shadow
  52. var $ShadowY = NULL; // Y Offset of the shadow
  53. var $ShadowR = NULL; // R component of the shadow
  54. var $ShadowG = NULL; // G component of the shadow
  55. var $ShadowB = NULL; // B component of the shadow
  56. var $Shadowa = NULL; // Alpha level of the shadow
  57. /* Image map */
  58. var $ImageMap = NULL; // Aray containing the image map
  59. var $ImageMapIndex = "pChart"; // Name of the session array
  60. var $ImageMapStorageMode = NULL; // Save the current imagemap storage mode
  61. var $ImageMapAutoDelete = TRUE; // Automatic deletion of the image map temp files
  62. /* Data Set */
  63. var $DataSet = NULL; // Attached dataset
  64. /* Last generated chart info */
  65. var $LastChartLayout = CHART_LAST_LAYOUT_REGULAR; // Last layout : regular or stacked
  66. /* Class constructor */
  67. function pImage($XSize,$YSize,$DataSet=NULL,$TransparentBackground=FALSE)
  68. {
  69. $this->TransparentBackground = $TransparentBackground;
  70. if ( $DataSet != NULL ) { $this->DataSet = $DataSet; }
  71. $this->XSize = $XSize;
  72. $this->YSize = $YSize;
  73. $this->Picture = imagecreatetruecolor($XSize,$YSize);
  74. if ( $this->TransparentBackground )
  75. {
  76. imagealphablending($this->Picture,FALSE);
  77. imagefilledrectangle($this->Picture, 0,0,$XSize, $YSize, imagecolorallocatealpha($this->Picture, 255, 255, 255, 127));
  78. imagealphablending($this->Picture,TRUE);
  79. imagesavealpha($this->Picture,true);
  80. }
  81. else
  82. {
  83. $C_White = $this->AllocateColor($this->Picture,255,255,255);
  84. imagefilledrectangle($this->Picture,0,0,$XSize,$YSize,$C_White);
  85. }
  86. }
  87. /* Enable / Disable and set shadow properties */
  88. function setShadow($Enabled=TRUE,$Format="")
  89. {
  90. $X = isset($Format["X"]) ? $Format["X"] : 2;
  91. $Y = isset($Format["Y"]) ? $Format["Y"] : 2;
  92. $R = isset($Format["R"]) ? $Format["R"] : 0;
  93. $G = isset($Format["G"]) ? $Format["G"] : 0;
  94. $B = isset($Format["B"]) ? $Format["B"] : 0;
  95. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 10;
  96. $this->Shadow = $Enabled;
  97. $this->ShadowX = $X;
  98. $this->ShadowY = $Y;
  99. $this->ShadowR = $R;
  100. $this->ShadowG = $G;
  101. $this->ShadowB = $B;
  102. $this->Shadowa = $Alpha;
  103. }
  104. /* Set the graph area position */
  105. function setGraphArea($X1,$Y1,$X2,$Y2)
  106. {
  107. if ( $X2 < $X1 || $X1 == $X2 || $Y2 < $Y1 || $Y1 == $Y2 ) { return(-1); }
  108. $this->GraphAreaX1 = $X1; $this->DataSet->Data["GraphArea"]["X1"] = $X1;
  109. $this->GraphAreaY1 = $Y1; $this->DataSet->Data["GraphArea"]["Y1"] = $Y1;
  110. $this->GraphAreaX2 = $X2; $this->DataSet->Data["GraphArea"]["X2"] = $X2;
  111. $this->GraphAreaY2 = $Y2; $this->DataSet->Data["GraphArea"]["Y2"] = $Y2;
  112. }
  113. /* Return the width of the picture */
  114. function getWidth()
  115. { return($this->XSize); }
  116. /* Return the heigth of the picture */
  117. function getHeight()
  118. { return($this->YSize); }
  119. /* Render the picture to a file */
  120. function render($FileName)
  121. {
  122. if ( $this->TransparentBackground ) { imagealphablending($this->Picture,false); imagesavealpha($this->Picture,true); }
  123. imagepng($this->Picture,$FileName);
  124. }
  125. /* Render the picture to a web browser stream */
  126. function stroke($BrowserExpire=FALSE)
  127. {
  128. if ( $this->TransparentBackground ) { imagealphablending($this->Picture,false); imagesavealpha($this->Picture,true); }
  129. if ( $BrowserExpire )
  130. {
  131. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  132. header("Cache-Control: no-cache");
  133. header("Pragma: no-cache");
  134. }
  135. header('Content-type: image/png');
  136. imagepng($this->Picture);
  137. }
  138. /* Automatic output method based on the calling interface */
  139. function autoOutput($FileName="output.png")
  140. {
  141. if (php_sapi_name() == "cli")
  142. $this->Render($FileName);
  143. else
  144. $this->Stroke();
  145. }
  146. /* Return the length between two points */
  147. function getLength($X1,$Y1,$X2,$Y2)
  148. { return(sqrt(pow(max($X1,$X2)-min($X1,$X2),2)+pow(max($Y1,$Y2)-min($Y1,$Y2),2))); }
  149. /* Return the orientation of a line */
  150. function getAngle($X1,$Y1,$X2,$Y2)
  151. {
  152. $Opposite = $Y2 - $Y1; $Adjacent = $X2 - $X1;$Angle = rad2deg(atan2($Opposite,$Adjacent));
  153. if ($Angle > 0) { return($Angle); } else { return(360-abs($Angle)); }
  154. }
  155. /* Return the surrounding box of text area */
  156. function getTextBox_deprecated($X,$Y,$FontName,$FontSize,$Angle,$Text)
  157. {
  158. $Size = imagettfbbox($FontSize,$Angle,$FontName,$Text);
  159. $Width = $this->getLength($Size[0],$Size[1],$Size[2],$Size[3])+1;
  160. $Height = $this->getLength($Size[2],$Size[3],$Size[4],$Size[5])+1;
  161. $RealPos[0]["X"] = $X; $RealPos[0]["Y"] = $Y;
  162. $RealPos[1]["X"] = cos((360-$Angle)*PI/180)*$Width + $RealPos[0]["X"]; $RealPos[1]["Y"] = sin((360-$Angle)*PI/180)*$Width + $RealPos[0]["Y"];
  163. $RealPos[2]["X"] = cos((270-$Angle)*PI/180)*$Height + $RealPos[1]["X"]; $RealPos[2]["Y"] = sin((270-$Angle)*PI/180)*$Height + $RealPos[1]["Y"];
  164. $RealPos[3]["X"] = cos((180-$Angle)*PI/180)*$Width + $RealPos[2]["X"]; $RealPos[3]["Y"] = sin((180-$Angle)*PI/180)*$Width + $RealPos[2]["Y"];
  165. $RealPos[TEXT_ALIGN_BOTTOMLEFT]["X"] = $RealPos[0]["X"]; $RealPos[TEXT_ALIGN_BOTTOMLEFT]["Y"] = $RealPos[0]["Y"];
  166. $RealPos[TEXT_ALIGN_BOTTOMRIGHT]["X"] = $RealPos[1]["X"]; $RealPos[TEXT_ALIGN_BOTTOMRIGHT]["Y"] = $RealPos[1]["Y"];
  167. return($RealPos);
  168. }
  169. /* Return the surrounding box of text area */
  170. function getTextBox($X,$Y,$FontName,$FontSize,$Angle,$Text)
  171. {
  172. $coords = imagettfbbox($FontSize, 0, $FontName, $Text);
  173. $a = deg2rad($Angle); $ca = cos($a); $sa = sin($a); $RealPos = array();
  174. for($i = 0; $i < 7; $i += 2)
  175. {
  176. $RealPos[$i/2]["X"] = $X + round($coords[$i] * $ca + $coords[$i+1] * $sa);
  177. $RealPos[$i/2]["Y"] = $Y + round($coords[$i+1] * $ca - $coords[$i] * $sa);
  178. }
  179. $RealPos[TEXT_ALIGN_BOTTOMLEFT]["X"] = $RealPos[0]["X"]; $RealPos[TEXT_ALIGN_BOTTOMLEFT]["Y"] = $RealPos[0]["Y"];
  180. $RealPos[TEXT_ALIGN_BOTTOMRIGHT]["X"] = $RealPos[1]["X"]; $RealPos[TEXT_ALIGN_BOTTOMRIGHT]["Y"] = $RealPos[1]["Y"];
  181. $RealPos[TEXT_ALIGN_TOPLEFT]["X"] = $RealPos[3]["X"]; $RealPos[TEXT_ALIGN_TOPLEFT]["Y"] = $RealPos[3]["Y"];
  182. $RealPos[TEXT_ALIGN_TOPRIGHT]["X"] = $RealPos[2]["X"]; $RealPos[TEXT_ALIGN_TOPRIGHT]["Y"] = $RealPos[2]["Y"];
  183. $RealPos[TEXT_ALIGN_BOTTOMMIDDLE]["X"] = ($RealPos[1]["X"]-$RealPos[0]["X"])/2+$RealPos[0]["X"]; $RealPos[TEXT_ALIGN_BOTTOMMIDDLE]["Y"] = ($RealPos[0]["Y"]-$RealPos[1]["Y"])/2+$RealPos[1]["Y"];
  184. $RealPos[TEXT_ALIGN_TOPMIDDLE]["X"] = ($RealPos[2]["X"]-$RealPos[3]["X"])/2+$RealPos[3]["X"]; $RealPos[TEXT_ALIGN_TOPMIDDLE]["Y"] = ($RealPos[3]["Y"]-$RealPos[2]["Y"])/2+$RealPos[2]["Y"];
  185. $RealPos[TEXT_ALIGN_MIDDLELEFT]["X"] = ($RealPos[0]["X"]-$RealPos[3]["X"])/2+$RealPos[3]["X"]; $RealPos[TEXT_ALIGN_MIDDLELEFT]["Y"] = ($RealPos[0]["Y"]-$RealPos[3]["Y"])/2+$RealPos[3]["Y"];
  186. $RealPos[TEXT_ALIGN_MIDDLERIGHT]["X"] = ($RealPos[1]["X"]-$RealPos[2]["X"])/2+$RealPos[2]["X"]; $RealPos[TEXT_ALIGN_MIDDLERIGHT]["Y"] = ($RealPos[1]["Y"]-$RealPos[2]["Y"])/2+$RealPos[2]["Y"];
  187. $RealPos[TEXT_ALIGN_MIDDLEMIDDLE]["X"] = ($RealPos[1]["X"]-$RealPos[3]["X"])/2+$RealPos[3]["X"]; $RealPos[TEXT_ALIGN_MIDDLEMIDDLE]["Y"] = ($RealPos[0]["Y"]-$RealPos[2]["Y"])/2+$RealPos[2]["Y"];
  188. return($RealPos);
  189. }
  190. /* Set current font properties */
  191. function setFontProperties($Format="")
  192. {
  193. $R = isset($Format["R"]) ? $Format["R"] : -1;
  194. $G = isset($Format["G"]) ? $Format["G"] : -1;
  195. $B = isset($Format["B"]) ? $Format["B"] : -1;
  196. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  197. $FontName = isset($Format["FontName"]) ? $Format["FontName"] : NULL;
  198. $FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : NULL;
  199. if ( $R != -1) { $this->FontColorR = $R; }
  200. if ( $G != -1) { $this->FontColorG = $G; }
  201. if ( $B != -1) { $this->FontColorB = $B; }
  202. if ( $Alpha != NULL) { $this->FontColorA = $Alpha; }
  203. if ( $FontName != NULL )
  204. $this->FontName = $FontName;
  205. if ( $FontSize != NULL )
  206. $this->FontSize = $FontSize;
  207. }
  208. /* Returns the 1st decimal values (used to correct AA bugs) */
  209. function getFirstDecimal($Value)
  210. {
  211. $Values = preg_split("/\./",$Value);
  212. if ( isset($Values[1]) ) { return(substr($Values[1],0,1)); } else { return(0); }
  213. }
  214. /* Attach a dataset to your pChart Object */
  215. function setDataSet(&$DataSet)
  216. { $this->DataSet = $DataSet; }
  217. /* Print attached dataset contents to STDOUT */
  218. function printDataSet()
  219. { print_r($this->DataSet); }
  220. /* Initialise the image map methods */
  221. function initialiseImageMap($Name="pChart",$StorageMode=IMAGE_MAP_STORAGE_SESSION,$UniqueID="imageMap",$StorageFolder="tmp")
  222. {
  223. $this->ImageMapIndex = $Name;
  224. $this->ImageMapStorageMode = $StorageMode;
  225. if ($StorageMode == IMAGE_MAP_STORAGE_SESSION)
  226. {
  227. if(!isset($_SESSION)) { session_start(); }
  228. $_SESSION[$this->ImageMapIndex] = NULL;
  229. }
  230. elseif($StorageMode == IMAGE_MAP_STORAGE_FILE)
  231. {
  232. $this->ImageMapFileName = $UniqueID;
  233. $this->ImageMapStorageFolder = $StorageFolder;
  234. if (file_exists($StorageFolder."/".$UniqueID.".map")) { unlink($StorageFolder."/".$UniqueID.".map"); }
  235. }
  236. }
  237. /* Add a zone to the image map */
  238. function addToImageMap($Type,$Plots,$Color=NULL,$Title=NULL,$Message=NULL,$HTMLEncode=FALSE)
  239. {
  240. if ( $this->ImageMapStorageMode == NULL ) { $this->initialiseImageMap(); }
  241. /* Encode the characters in the imagemap in HTML standards */
  242. $Title = str_replace("&#8364;","\u20AC",$Title);
  243. $Title = htmlentities($Title,ENT_QUOTES,"ISO-8859-15");
  244. if ( $HTMLEncode )
  245. {
  246. $Message = htmlentities($Message,ENT_QUOTES,"ISO-8859-15");
  247. $Message = str_replace("&lt;","<",$Message);
  248. $Message = str_replace("&gt;",">",$Message);
  249. }
  250. if ( $this->ImageMapStorageMode == IMAGE_MAP_STORAGE_SESSION )
  251. {
  252. if(!isset($_SESSION)) { $this->initialiseImageMap(); }
  253. $_SESSION[$this->ImageMapIndex][] = array($Type,$Plots,$Color,$Title,$Message);
  254. }
  255. elseif($this->ImageMapStorageMode == IMAGE_MAP_STORAGE_FILE)
  256. {
  257. $Handle = fopen($this->ImageMapStorageFolder."/".$this->ImageMapFileName.".map", 'a');
  258. fwrite($Handle, $Type.IMAGE_MAP_DELIMITER.$Plots.IMAGE_MAP_DELIMITER.$Color.IMAGE_MAP_DELIMITER.$Title.IMAGE_MAP_DELIMITER.$Message."\r\n");
  259. fclose($Handle);
  260. }
  261. }
  262. /* Remove VOID values from an imagemap custom values array */
  263. function removeVOIDFromArray($SerieName, $Values)
  264. {
  265. if ( !isset($this->DataSet->Data["Series"][$SerieName]) ) { return(-1); }
  266. $Result = "";
  267. foreach($this->DataSet->Data["Series"][$SerieName]["Data"] as $Key => $Value)
  268. { if ( $Value != VOID && isset($Values[$Key]) ) { $Result[] = $Values[$Key]; } }
  269. return($Result);
  270. }
  271. /* Replace the title of one image map serie */
  272. function replaceImageMapTitle($OldTitle, $NewTitle)
  273. {
  274. if ( $this->ImageMapStorageMode == NULL ) { return(-1); }
  275. if ( is_array($NewTitle) ) { $NewTitle = $this->removeVOIDFromArray($OldTitle, $NewTitle); }
  276. if ( $this->ImageMapStorageMode == IMAGE_MAP_STORAGE_SESSION )
  277. {
  278. if(!isset($_SESSION)) { return(-1); }
  279. if ( is_array($NewTitle) )
  280. { $ID = 0; foreach($_SESSION[$this->ImageMapIndex] as $Key => $Settings) { if ( $Settings[3] == $OldTitle && isset($NewTitle[$ID])) { $_SESSION[$this->ImageMapIndex][$Key][3] = $NewTitle[$ID]; $ID++; } } }
  281. else
  282. { foreach($_SESSION[$this->ImageMapIndex] as $Key => $Settings) { if ( $Settings[3] == $OldTitle ) { $_SESSION[$this->ImageMapIndex][$Key][3] = $NewTitle; } } }
  283. }
  284. elseif( $this->ImageMapStorageMode == IMAGE_MAP_STORAGE_FILE )
  285. {
  286. $TempArray = "";
  287. $Handle = @fopen($this->ImageMapStorageFolder."/".$this->ImageMapFileName.".map", "r");
  288. if ($Handle)
  289. {
  290. while (($Buffer = fgets($Handle, 4096)) !== false)
  291. {
  292. $Fields = preg_split("/".IMAGE_MAP_DELIMITER."/",str_replace(array(chr(10),chr(13)),"",$Buffer));
  293. $TempArray[] = array($Fields[0],$Fields[1],$Fields[2],$Fields[3],$Fields[4]);
  294. }
  295. fclose($Handle);
  296. if ( is_array($NewTitle) )
  297. { $ID = 0; foreach($TempArray as $Key => $Settings) { if ( $Settings[3] == $OldTitle && isset($NewTitle[$ID]) ) { $TempArray[$Key][3] = $NewTitle[$ID]; $ID++; } } }
  298. else
  299. { foreach($TempArray as $Key => $Settings) { if ( $Settings[3] == $OldTitle ) { $TempArray[$Key][3] = $NewTitle; } } }
  300. $Handle = fopen($this->ImageMapStorageFolder."/".$this->ImageMapFileName.".map", 'w');
  301. foreach($TempArray as $Key => $Settings)
  302. { fwrite($Handle, $Settings[0].IMAGE_MAP_DELIMITER.$Settings[1].IMAGE_MAP_DELIMITER.$Settings[2].IMAGE_MAP_DELIMITER.$Settings[3].IMAGE_MAP_DELIMITER.$Settings[4]."\r\n"); }
  303. fclose($Handle);
  304. }
  305. }
  306. }
  307. /* Replace the values of the image map contents */
  308. function replaceImageMapValues($Title, $Values)
  309. {
  310. if ( $this->ImageMapStorageMode == NULL ) { return(-1); }
  311. $Values = $this->removeVOIDFromArray($Title, $Values);
  312. $ID = 0;
  313. if ( $this->ImageMapStorageMode == IMAGE_MAP_STORAGE_SESSION )
  314. {
  315. if(!isset($_SESSION)) { return(-1); }
  316. foreach($_SESSION[$this->ImageMapIndex] as $Key => $Settings) { if ( $Settings[3] == $Title ) { if ( isset($Values[$ID]) ) { $_SESSION[$this->ImageMapIndex][$Key][4] = $Values[$ID]; } $ID++; } }
  317. }
  318. elseif( $this->ImageMapStorageMode == IMAGE_MAP_STORAGE_FILE )
  319. {
  320. $TempArray = "";
  321. $Handle = @fopen($this->ImageMapStorageFolder."/".$this->ImageMapFileName.".map", "r");
  322. if ($Handle)
  323. {
  324. while (($Buffer = fgets($Handle, 4096)) !== false)
  325. {
  326. $Fields = preg_split("/".IMAGE_MAP_DELIMITER."/",str_replace(array(chr(10),chr(13)),"",$Buffer));
  327. $TempArray[] = array($Fields[0],$Fields[1],$Fields[2],$Fields[3],$Fields[4]);
  328. }
  329. fclose($Handle);
  330. foreach($TempArray as $Key => $Settings) { if ( $Settings[3] == $Title ) { if ( isset($Values[$ID]) ) { $TempArray[$Key][4] = $Values[$ID]; } $ID++; } }
  331. $Handle = fopen($this->ImageMapStorageFolder."/".$this->ImageMapFileName.".map", 'w');
  332. foreach($TempArray as $Key => $Settings)
  333. { fwrite($Handle, $Settings[0].IMAGE_MAP_DELIMITER.$Settings[1].IMAGE_MAP_DELIMITER.$Settings[2].IMAGE_MAP_DELIMITER.$Settings[3].IMAGE_MAP_DELIMITER.$Settings[4]."\r\n"); }
  334. fclose($Handle);
  335. }
  336. }
  337. }
  338. /* Dump the image map */
  339. function dumpImageMap($Name="pChart",$StorageMode=IMAGE_MAP_STORAGE_SESSION,$UniqueID="imageMap",$StorageFolder="tmp")
  340. {
  341. $this->ImageMapIndex = $Name;
  342. $this->ImageMapStorageMode = $StorageMode;
  343. if ( $this->ImageMapStorageMode == IMAGE_MAP_STORAGE_SESSION )
  344. {
  345. if(!isset($_SESSION)) { session_start(); }
  346. if ( $_SESSION[$Name] != NULL )
  347. {
  348. foreach($_SESSION[$Name] as $Key => $Params)
  349. { echo $Params[0].IMAGE_MAP_DELIMITER.$Params[1].IMAGE_MAP_DELIMITER.$Params[2].IMAGE_MAP_DELIMITER.$Params[3].IMAGE_MAP_DELIMITER.$Params[4]."\r\n"; }
  350. }
  351. }
  352. elseif( $this->ImageMapStorageMode == IMAGE_MAP_STORAGE_FILE )
  353. {
  354. if (file_exists($StorageFolder."/".$UniqueID.".map"))
  355. {
  356. $Handle = @fopen($StorageFolder."/".$UniqueID.".map", "r");
  357. if ($Handle) { while (($Buffer = fgets($Handle, 4096)) !== false) { echo $Buffer; } }
  358. fclose($Handle);
  359. if ( $this->ImageMapAutoDelete ) { unlink($StorageFolder."/".$UniqueID.".map"); }
  360. }
  361. }
  362. /* When the image map is returned to the client, the script ends */
  363. exit();
  364. }
  365. /* Return the HTML converted color from the RGB composite values */
  366. function toHTMLColor($R,$G,$B)
  367. {
  368. $R=intval($R); $G=intval($G); $B=intval($B);
  369. $R=dechex($R<0?0:($R>255?255:$R)); $G=dechex($G<0?0:($G>255?255:$G));$B=dechex($B<0?0:($B>255?255:$B));
  370. $Color="#".(strlen($R) < 2?'0':'').$R; $Color.=(strlen($G) < 2?'0':'').$G; $Color.= (strlen($B) < 2?'0':'').$B;
  371. return($Color);
  372. }
  373. /* Reverse an array of points */
  374. function reversePlots($Plots)
  375. {
  376. $Result = "";
  377. for($i=count($Plots)-2;$i>=0;$i=$i-2) { $Result[] = $Plots[$i]; $Result[] = $Plots[$i+1]; }
  378. return($Result);
  379. }
  380. /* Mirror Effect */
  381. function drawAreaMirror($X,$Y,$Width,$Height,$Format="")
  382. {
  383. $StartAlpha = isset($Format["StartAlpha"]) ? $Format["StartAlpha"] : 80;
  384. $EndAlpha = isset($Format["EndAlpha"]) ? $Format["EndAlpha"] : 0;
  385. $AlphaStep = ($StartAlpha-$EndAlpha)/$Height;
  386. $Picture = imagecreatetruecolor($this->XSize,$this->YSize);
  387. imagecopy($Picture,$this->Picture,0,0,0,0,$this->XSize,$this->YSize);
  388. for($i=1;$i<=$Height;$i++)
  389. {
  390. if ( $Y+($i-1) < $this->YSize && $Y-$i > 0 ) { imagecopymerge($Picture,$this->Picture,$X,$Y+($i-1),$X,$Y-$i,$Width,1,$StartAlpha-$AlphaStep*$i); }
  391. }
  392. imagecopy($this->Picture,$Picture,0,0,0,0,$this->XSize,$this->YSize);
  393. }
  394. }

Constants

Classes

Namesort descending Description
pImage