pImage.class.php 19 KB

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