PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/quicky/classes/plugins/Captcha/imagedraw.class.php

https://bitbucket.org/seyar/ari100krat.local
PHP | 629 lines | 566 code | 27 blank | 36 comment | 90 complexity | 579534969a6577a2aa93fe5d1a440d38 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
  1. <?php
  2. /**************************************************************************/
  3. /* 0xENGINE: Web Site */
  4. /* =========================== */
  5. /* (c)oded 2006 by white phoenix */
  6. /* http://whitephoenix.ru */
  7. /* */
  8. /* This program is free software. You can't redistribute it and/or modify */
  9. /* it under the terms of the GNU General Public License as published by */
  10. /* the Free Software Foundation; either version 2 of the License. */
  11. /* */
  12. /* core-imagedraw.php: Image Draw */
  13. /**************************************************************************/
  14. if (!function_exists('win2uni')) {
  15. function win2uni($s) {
  16. $s = convert_cyr_string($s,'w','i');
  17. for ($result='',$i=0; $i<strlen($s); $i++) {
  18. $charcode = ord($s[$i]);
  19. $result .= ($charcode>175)?'&#'.(1040+($charcode-176)).';':$s[$i];
  20. }
  21. return $result;
  22. }
  23. }
  24. define('MIRROR_HORIZONTAL',1);
  25. define('MIRROR_VERTICAL',2);
  26. define('MIRROR_BOTH',3);
  27. define('VERTICAL',1);
  28. define('HORIZONTAL',2);
  29. class imagedraw {
  30. var $res;
  31. var $W;
  32. var $H;
  33. var $scale = 1;
  34. var $cX;
  35. var $cY;
  36. var $colors = array();
  37. var $type = 'png';
  38. var $quality = 100;
  39. var $outfile = '';
  40. var $offsetX = 0;
  41. var $offsetY = 0;
  42. var $colortransparent;
  43. function imagedraw() {
  44. $this->init();
  45. }
  46. function init() {
  47. $this->sW = $this->W*$this->scale;
  48. $this->sH = $this->H*$this->scale;
  49. $this->cX = $this->W/2;
  50. $this->cY = $this->H/2;
  51. $this->set_offset($this->offsetX,$this->offsetY);
  52. }
  53. function sY() {
  54. return imagesy($this->res);
  55. }
  56. function sX() {
  57. return imagesx($this->res);
  58. }
  59. function set_offset($offsetX,$offsetY) {
  60. $this->offsetX = $offsetX*$this->scale;
  61. $this->offsetY = $offsetY*$this->scale;
  62. }
  63. function hex2color($color,$d=false) {
  64. if (is_resource($color)) {
  65. return $color;
  66. }
  67. if (is_string($color)) {
  68. $color = hexdec($color);
  69. }
  70. if (is_int($color)) {
  71. $color = sprintf('%06x',$color);
  72. }
  73. if (isset($this->colors[$color])) {
  74. return $this->colors[$color];
  75. }
  76. return $this->colors[$color] = imagecolorallocate($this->res,hexdec(substr($color,0,2)),hexdec(substr($color,2,2)),hexdec(substr($color,4,2)));
  77. }
  78. function createfromstring($string) {
  79. $this->res = imagecreatefromstring($string);
  80. }
  81. function createfromjpeg($file) {
  82. $this->res = imagecreatefromjpeg($file);
  83. }
  84. function createtruecolor($w=NULL,$h=NULL) {
  85. if (is_null($w)) {
  86. return $this->res = imagecreatetruecolor($this->sW+$this->offsetX,$this->sH+$this->offsetY);
  87. }
  88. else {
  89. return $this->res = imagecreatetruecolor($w,$h);
  90. }
  91. }
  92. function colorat($x,$y) {
  93. return imagecolorat($this->res,$x+$this->offsetX,$y+$this->offsetY);
  94. }
  95. function create($w=NULL,$h=NULL) {
  96. if (is_null($w)) {
  97. return $this->res = imagecreate($this->sW+$this->offsetX,$this->sH+$this->offsetY);
  98. }
  99. else {
  100. return $this->res = imagecreate($w,$h);
  101. }
  102. }
  103. function out() {
  104. if ($this->type == 'png') {
  105. return $this->outfile != ''?imagepng($this->res,strval($this->outfile)):imagepng($this->res);
  106. }
  107. elseif ($this->type == 'jpeg') {
  108. return $this->outfile != ''?imagejpeg($this->res,strval($this->outfile),$this->quality):imagejpeg($this->res,NULL,$this->quality);
  109. }
  110. elseif ($this->type == 'gif') {
  111. return $this->outfile != ''?imagegif($this->res,strval($this->outfile)):imagegif($this->res);
  112. }
  113. }
  114. function setbgcolor($color = 0xFFFFFF) {
  115. return imagefill($this->res,0,0,$this->hex2color($color));
  116. }
  117. function border($color = 0x000000) {
  118. return imageRectangle($this->res,
  119. $this->offsetX, $this->offsetY,
  120. $this->sW+$this->offsetX-1, $this->sH+$this->offsetY-1,
  121. $this->hex2color($color));
  122. }
  123. function border2($color = 0x000000) {
  124. return imageRectangle($this->res,
  125. $this->offsetX, $this->offsetY,
  126. $this->sW+$this->offsetX, $this->sH+$this->offsetY,
  127. $this->hex2color($color));
  128. }
  129. function rscale($a) {
  130. return $a/$this->scale;
  131. }
  132. function tscale($a) {
  133. return $a*$this->scale;
  134. }
  135. function setScale($s) {
  136. return $this->scale = floatval($s);
  137. }
  138. function setpixel($x,$y,$color = 0x000000) {
  139. return imagesetpixel($this->res,$this->offsetX+$x,$this->offsetY+$y,$this->hex2color($color));
  140. }
  141. function line($x1,$y1,$x2,$y2,$color = 0x000000,$thick = 1) {
  142. $x1 = $x1*$this->scale+$this->offsetX;
  143. $x2 = $x2*$this->scale+$this->offsetX;
  144. $y1 = $y1*$this->scale+$this->offsetY;
  145. $y2 = $y2*$this->scale+$this->offsetY;
  146. $color = $this->hex2color($color);
  147. if ($thick == 1) {
  148. return imageline($this->res,$x1,$y1,$x2,$y2,$color);
  149. }
  150. $t = $thick/2-0.5;
  151. if ($x1 == $x2 || $y1 == $y2) {
  152. return imagefilledrectangle($this->res,round(min($x1,$x2)-$t),round(min($y1,$y2)-$t),round(max($x1,$x2)+$t),round(max($y1,$y2)+$t),$color);
  153. }
  154. $k = ($y2 - $y1) / ($x2 - $x1); //y = kx + q
  155. $a = $t / sqrt(1 + pow($k,2));
  156. $points = array(
  157. round($x1-(1+$k)*$a),round($y1+(1-$k)*$a),
  158. round($x1-(1-$k)*$a),round($y1-(1+$k)*$a),
  159. round($x2+(1+$k)*$a),round($y2-(1-$k)*$a),
  160. round($x2+(1-$k)*$a),round($y2+(1+$k)*$a),
  161. );
  162. imagefilledpolygon($this->res,$points,4,$color);
  163. imagepolygon($this->res,$points,4,$color);
  164. return;
  165. }
  166. function line1($x1,$y1,$x2,$y2,$color = 0x000000,$thickness=5) {
  167. imagesetthickness($this->res,$thickness);
  168. imageline($this->res,
  169. $this->offsetX+$x1*$this->scale, $this->offsetY-1+$y1*$this->scale,
  170. $this->offsetX+$x2*$this->scale, $this->offsetY-1+$y2*$this->scale,
  171. $this->hex2color($color));
  172. imagesetthickness($this->res,1);
  173. }
  174. function ttftext($text,$color,$font,$size,$x,$y,$angle=0) {
  175. if (!is_file($font) or !is_readable($font)) {
  176. user_error('Can\'t open font '.$font,E_USER_WARNING);
  177. return;
  178. }
  179. return imagettftext($this->res,$size*$this->scale,$angle,
  180. $this->offsetX+$x*$this->scale,
  181. $this->offsetY+$y*$this->scale,
  182. $this->hex2color($color),$font,win2uni($text));
  183. }
  184. function arc($cx,$cy,$w,$h,$s,$e,$color = 0x000000) {
  185. return imagearc($this->res,$cx+$this->offsetX,$cy+$this->offsetY,$w,$h,$s,$e,$this->hex2color($color));
  186. }
  187. function filledarc($cx,$cy,$w,$h,$s,$e,$color = 0x000000) {
  188. return imagefilledarc($this->res,$cx+$this->offsetX,$cy+$this->offsetY,$w,$h,$s,$e,$this->hex2color($color));
  189. }
  190. function ellipse($cx,$cy,$w,$h,$color = 0x000000) {
  191. return imageellipse($this->res,$cx+$this->offsetX,$cy+$this->offsetY,$w,$h,$s,$e,$this->hex2color($color));
  192. }
  193. function filledellipse($cx,$cy,$w,$h,$color = 0x000000) {
  194. return imagefilledellipse($this->res,$cx+$this->offsetX,$cy+$this->offsetY,$w,$h,$this->hex2color($color));
  195. }
  196. function pointmark($x,$y,$name=NULL,$color = 0x000000) {
  197. $this->filledellipse($x,$y,5,5,$color);
  198. if (is_null($name)) {
  199. $name = '('.round($x,3).','.round($y,3).')';
  200. }
  201. $this->ttftext($name,$color,CORE_PATH.'fonts/ARIAL.TTF',9,$x+5,$y-5);
  202. }
  203. function filledpolygon($points,$color = 0x000000) {
  204. if (!is_array($points)) {
  205. return FALSE;
  206. }
  207. else {
  208. $points = array_values($points);
  209. $points = array_map('intval',$points);
  210. }
  211. foreach ($points as $i=>$v) {
  212. $points[$i] = $v*$this->scale+(($i%2 == 0)?$this->offsetX:$this->offsetY);
  213. }
  214. return imagefilledpolygon($this->res,$points,sizeof($points)/2,$this->hex2color($color));
  215. }
  216. function polygon($points,$color = 0x000000) {
  217. if (!is_array($points)) {
  218. return FALSE;
  219. }
  220. else {
  221. $points = array_values($points);
  222. $points = array_map('intval',$points);
  223. }
  224. foreach ($points as $i=>$v) {
  225. $points[$i] = $v*$this->scale+(($i%2 == 0)?$this->offsetX:$this->offsetY);
  226. }
  227. return imagefilledpolygon($this->res,$points,sizeof($points)/2,$this->hex2color($color));
  228. }
  229. function antialias($bool) {
  230. imageantialias($this->res,!!$bool);
  231. }
  232. function colortransparent($color = 0xFFFFFF) {
  233. return imagecolortransparent($this->res,$this->colortransparent = $this->hex2color($color));
  234. }
  235. function filter_twirl($dimx=NULL,$dimy=NULL) {
  236. if (is_null($dimx)) {
  237. $dimx = $this->W-1;
  238. }
  239. if (is_null($dimy)) {
  240. $dimy = $this->H-1;
  241. }
  242. $wp = $dimx/2;
  243. $hp = $dimy/2;
  244. $im_source = imagecreatetruecolor($dimx,$dimy);
  245. imagecopy($im_source,$this->res,
  246. 0,0,
  247. 0,0,
  248. $dimx,$dimy
  249. );
  250. $im_filter = imagecreatetruecolor($dimx+100,$dimy+100);
  251. imagealphablending($im_filter,FALSE);
  252. imagesavealpha($im_filter,TRUE);
  253. $color_filter = imagecolorallocatealpha($im_filter,255,255,255,127);
  254. imagefill($im_filter,0,0,$color_filter);
  255. $a = atan2(-1.0,$wp-1.0);
  256. if ($a < 0.0) {
  257. $a += 2.0*M_PI;
  258. }
  259. $dx = $dimx / $a;
  260. $d = sqrt($hp*$hp+$wp*$wp);
  261. $dy = $dimy / $d;
  262. for ($h = 0; $h < $dimy + 1; $h++) {
  263. for ($w = 0; $w < $dimx + 1; $w++) {
  264. $x = ($w-$wp);
  265. $y = ($h-$hp);
  266. $dist = sqrt($x*$x+$y*$y);
  267. $angle = atan2($y,$x);
  268. if ($angle < 0) {
  269. $angle += 2.0 * M_PI;
  270. }
  271. $rgb = imagecolorat($this->res,(int)($dimx - $dx*$angle),(int)($dy*$dist));
  272. $a = ($rgb >> 24) & 0xFF;
  273. $r = ($rgb >> 16) & 0xFF;
  274. $g = ($rgb >> 8) & 0xFF;
  275. $b = $rgb & 0xFF;
  276. $color_filter = imagecolorallocatealpha($im_filter,$r,$g,$b,$a);
  277. imagesetpixel($im_filter,$w,$h,$color_filter);
  278. }
  279. }
  280. imagecopy($this->res,$im_filter,
  281. 0,0,
  282. 0,0,
  283. $dimx,$dimy
  284. );
  285. imagedestroy($im_filter);
  286. }
  287. function filter_swirl($dimx=NULL,$dimy=NULL) {
  288. if (is_null($dimx)) {
  289. $dimx = $this->W;
  290. }
  291. if (is_null($dimy)) {
  292. $dimy = $this->H;
  293. }
  294. $wp = $dimx/2;
  295. $hp = $dimy/2;
  296. $im_source = imagecreatetruecolor($dimx,$dimy);
  297. imagecopy($im_source,$this->res,
  298. 0,0,
  299. 0,0,
  300. $dimx,$dimy
  301. );
  302. $im_filter = imagecreatetruecolor($dimx,$dimy);
  303. imagealphablending($im_filter,FALSE);
  304. imagesavealpha($im_filter,TRUE);
  305. $color_filter = imagecolorallocatealpha($im_filter,255,255,255,127);
  306. imagefill($im_filter,0,0,$color_filter);
  307. $dz = -0.01;
  308. for ($h = 0; $h < $dimy + 1; $h++) {
  309. for ($w = 0; $w < $dimx + 1; $w++) {
  310. $x = ($w - $wp);
  311. $y = ($h - $hp);
  312. $dist = sqrt($x*$x + $y*$y);
  313. $angle = atan2($y,$x);
  314. if ($angle < 0) {
  315. $angle += 2.0 * M_PI;
  316. }
  317. @$rgb = imagecolorat($im_source,(int) ($wp + $dist * cos($angle + $dist * $dz)),(int)($hp + $dist * sin($angle + $dist * $dz)));
  318. $a = ($rgb >> 24) & 0xFF;
  319. $r = ($rgb >> 16) & 0xFF;
  320. $g = ($rgb >> 8) & 0xFF;
  321. $b = $rgb & 0xFF;
  322. $color_filter = imagecolorallocatealpha($im_filter,$r,$g,$b,$a);
  323. imagesetpixel($im_filter,$w,$h,$color_filter);
  324. }
  325. }
  326. imagecopy($this->res,$im_filter,
  327. 0,0,
  328. 0,0,
  329. $dimx,$dimy
  330. );
  331. //imagedestroy($im_source);
  332. //imagedestroy($im_filter);
  333. }
  334. function wave_region($x,$y,$width,$height,$grade=10) {
  335. for ($i = 0; $i < $width; $i += 2) {
  336. imagecopy($this->res,$this->res,
  337. $x+$i-2,$y+sin($i/10)*$grade, //dest
  338. $x+$i,$y, //src
  339. 2,$height);
  340. }
  341. }
  342. function resize_file($src,$dest,$width,$height,$rgb = 0xFFFFFF,$quality = 100) {
  343. $size = getimagesize($src);
  344. if (!$size) return -1;
  345. if (($size[0] <= $width) && ($size[1] <= $height)) {
  346. return copy($src,$dest);
  347. }
  348. $format = strtolower(substr($size['mime'], strpos($size['mime'], '/')+1));
  349. $icfunc = 'imagecreatefrom'.$format;
  350. if (!function_exists($icfunc)) {
  351. return -2;
  352. }
  353. $x_ratio = $width / $size[0];
  354. $y_ratio = $height / $size[1];
  355. $ratio = min($x_ratio, $y_ratio);
  356. $use_x_ratio = ($x_ratio == $ratio);
  357. $new_width = $use_x_ratio ? $width : floor($size[0] * $ratio);
  358. $new_height = !$use_x_ratio ? $height : floor($size[1] * $ratio);
  359. $new_left = $use_x_ratio ? 0 : floor(($width - $new_width) / 2);
  360. $new_top = !$use_x_ratio ? 0 : floor(($height - $new_height) / 2);
  361. $isrc = $icfunc($src);
  362. //$idest = imagecreatetruecolor($width, $height);
  363. $idest = imagecreatetruecolor($new_width, $new_height);
  364. $new_left = $new_top = 0;
  365. imagefill($idest, 0, 0, $rgb);
  366. imagecopyresampled($idest, $isrc, $new_left, $new_top, 0, 0,
  367. $new_width, $new_height, $size[0], $size[1]);
  368. imagejpeg($idest,$dest,$quality);
  369. imagedestroy($isrc);
  370. imagedestroy($idest);
  371. return TRUE;
  372. }
  373. function skew($skew_val) {
  374. $width = $this->sX();
  375. $height = $this->sY();
  376. $imgdest = imagecreatetruecolor($width,$height+($height*$skew_val));
  377. $trans = imagecolorallocate($imgdest,0,0,0);
  378. $temp = 0;
  379. for($x = 0; $x < $width; $x++) {
  380. for($y = 0; $y < $height; $y++) {
  381. imagecopy($imgdest,$this->res,$x,$y+$temp,$x,$y,1,1);
  382. imagecolortransparent($imgdest,$trans);
  383. }
  384. $temp += $skew_val;
  385. }
  386. $this->destroy();
  387. $this->res = $imgdest;
  388. }
  389. function flip($mode) {
  390. $w = $this->sX();
  391. $h = $this->sY();
  392. $flipped = imagecreatetruecolor($w,$h);
  393. if ($mode & VERTICAL) {
  394. for ($y = 0; $y < $h; $y++) {
  395. imagecopy($flipped,$this->res,0,$y,0,$h - $y - 1,$w,1);
  396. }
  397. }
  398. if ($mode & HORIZONTAL) {
  399. for ($x = 0; $x < $w; $x++) {
  400. imagecopy($flipped,$this->res,$x,0,$w - $x - 1,0,1,$h);
  401. }
  402. }
  403. $this->res = $flipped;
  404. }
  405. function mirror($type=1) {
  406. $imgsrc = $this->res;
  407. $width = $this->sX();
  408. $height = $this->sY();
  409. $imgdest = imagecreatetruecolor($width,$height);
  410. for ($x=0 ; $x<$width ; $x++) {
  411. for ($y=0 ; $y<$height ; $y++) {
  412. if ($type == MIRROR_HORIZONTAL) imagecopy($imgdest,$imgsrc,$width-$x-1,$y,$x,$y,1,1);
  413. if ($type == MIRROR_VERTICAL) imagecopy($imgdest,$imgsrc,$x,$height-$y-1,$x,$y,1,1);
  414. if ($type == MIRROR_BOTH) imagecopy($imgdest,$imgsrc,$width-$x-1,$height-$y-1,$x,$y,1,1);
  415. }
  416. }
  417. $this->destroy();
  418. $this->res = $imgdest;
  419. }
  420. function watermark($img) {
  421. $bwidth = $this->sX();
  422. $bheight = $this->xY();
  423. $lwidth = imagesx($img);
  424. $lheight = imagesy($img);
  425. $src_x = $bwidth - ($lwidth + 5);
  426. $src_y = $bheight - ($lheight + 5);
  427. imageAlphaBlending($this->res,TRUE);
  428. imagecopy($this->res,$img,$src_x,$src_y,0,0,$lwidth,$lheight);
  429. }
  430. function skew_waves() {
  431. $width = $this->sx();
  432. $height = $this->sY();
  433. $img = $this->res;
  434. $img2 = imagecreatetruecolor($width,$height);
  435. $center = $width/2;
  436. // periods
  437. $rand1=mt_rand(750000,1200000)/10000000;
  438. $rand2=mt_rand(750000,1200000)/10000000;
  439. $rand3=mt_rand(750000,1200000)/10000000;
  440. $rand4=mt_rand(750000,1200000)/10000000;
  441. // phases
  442. $rand5=mt_rand(0,31415926)/10000000;
  443. $rand6=mt_rand(0,31415926)/10000000;
  444. $rand7=mt_rand(0,31415926)/10000000;
  445. $rand8=mt_rand(0,31415926)/10000000;
  446. // amplitudes
  447. $rand9=mt_rand(330,420)/110;
  448. $rand10=mt_rand(330,450)/110;
  449. $foreground_color = array(0x00,0x00,0x00);
  450. $background_color = array(0xC0,0xC0,0xC0);
  451. //wave distortion
  452. $jjj = 0;
  453. for($x=0;$x<$width;$x++) {
  454. for($y=0;$y<$height;$y++) {
  455. $sx=$x+(sin($x*$rand1+$rand5)+sin($y*$rand3+$rand6))*$rand9-$width/2+$center+1;
  456. $sy=$y+(sin($x*$rand2+$rand7)+sin($y*$rand4+$rand8))*$rand10;
  457. if($sx<0 || $sy<0 || $sx>=$width-1 || $sy>=$height-1) {
  458. continue;
  459. }else {
  460. $color=imagecolorat($img, $sx, $sy) & 0xFF;
  461. $color_x=imagecolorat($img, $sx+1, $sy) & 0xFF;
  462. $color_y=imagecolorat($img, $sx, $sy+1) & 0xFF;
  463. $color_xy=imagecolorat($img, $sx+1, $sy+1) & 0xFF;
  464. }
  465. if($color==255 && $color_x==255 && $color_y==255 && $color_xy==255) {
  466. continue;
  467. }else if($color==0 && $color_x==0 && $color_y==0 && $color_xy==0) {
  468. $newred=$foreground_color[0];
  469. $newgreen=$foreground_color[1];
  470. $newblue=$foreground_color[2];
  471. $newred = 0x00;
  472. $newgreen = 0x00;
  473. $newblue = 0x00;
  474. //++$jjj;
  475. }else {
  476. $frsx=$sx-floor($sx);
  477. $frsy=$sy-floor($sy);
  478. $frsx1=1-$frsx;
  479. $frsy1=1-$frsy;
  480. $newcolor=(
  481. $color*$frsx1*$frsy1+
  482. $color_x*$frsx*$frsy1+
  483. $color_y*$frsx1*$frsy+
  484. $color_xy*$frsx*$frsy);
  485. if($newcolor>255) $newcolor=255;
  486. $newcolor=$newcolor/255;
  487. $newcolor0=1-$newcolor;
  488. $newred=$newcolor0*$foreground_color[0]+$newcolor*$background_color[0];
  489. $newgreen=$newcolor0*$foreground_color[1]+$newcolor*$background_color[1];
  490. $newblue=$newcolor0*$foreground_color[2]+$newcolor*$background_color[2];
  491. }
  492. imagesetpixel($img2, $x, $y, imagecolorallocate($img2, $newred, $newgreen, $newblue));
  493. }
  494. }
  495. for($x=0;$x<$width;$x++) {
  496. for($y=0;$y<=$height;$y++) {
  497. if (($y > $height-4) || (imagecolorat($img2,$x,$y) == 0x171717)) {
  498. imagesetpixel($img2,$x,$y,0x000000);
  499. }
  500. }
  501. }
  502. $this->destroy();
  503. $this->res = $img2;
  504. }
  505. function destroy() {
  506. return imagedestroy($this->res);
  507. }
  508. }
  509. class diagramm {
  510. var $colors = array();
  511. var $legend = array();
  512. var $shadows = array();
  513. var $values;
  514. var $draw;
  515. function draw() {
  516. $black = ImageColorAllocate($this->draw->res,0,0,0);
  517. // ������� ������� �����������
  518. $W = $this->draw->sX();
  519. $H = $this->draw->sY();
  520. $this->draw->antialias(TRUE);
  521. // ����� ������� #####################################
  522. // ��������� ���������� �������,�� ����� ������� ������ �������
  523. $this->legend_count = sizeof($this->legend);
  524. // ��������� ������������ ����� ������,�� ����� ������� ������ �������
  525. $max_length = 0;
  526. foreach($this->legend as $v) {
  527. if ($max_length < strlen($v)) {
  528. $max_length = strlen($v);
  529. }
  530. }
  531. // ����� ������,������� �� ����� �������� �������
  532. $FONT = 2;
  533. $font_w = ImageFontWidth($FONT);
  534. $font_h = ImageFontHeight($FONT);
  535. // ����� �������������� - ������� ������� ----------------------------
  536. $l_width = ($font_w*$max_length)+$font_h+10+5+10;
  537. $l_height = $font_h*$this->legend_count+10+10;
  538. // ������� ���������� �������� ������ ���� �������������� - ������� �������
  539. $l_x1 = $W-100-$l_width;
  540. $l_y1 = ($H-$l_height)/2;
  541. // ������ �������������� - ������� �������
  542. ImageRectangle($this->draw->res,$l_x1,$l_y1,$l_x1+$l_width,$l_y1+$l_height,$black);
  543. // ����� ����� ������� � ������� �����������
  544. $text_x = $l_x1+10+5+$font_h;
  545. $square_x = $l_x1+10;
  546. $y = $l_y1+10;
  547. $i = 0;
  548. foreach($this->legend as $v) {
  549. $dy = $y+($i*$font_h);
  550. $this->draw->ttftext($v,$black,CORE_PATH.'fonts/TAHOMA.TTF',8,$text_x,$dy+11);
  551. ImageFilledRectangle($this->draw->res,
  552. $square_x+1,$dy+1,$square_x+$font_h-1,$dy+$font_h-1,
  553. $this->draw->hex2color($this->colors[$i]));
  554. ImageRectangle($this->draw->res,
  555. $square_x+1,$dy+1,$square_x+$font_h-1,$dy+$font_h-1,
  556. $black);
  557. $i++;
  558. }
  559. // ����� �������� ��������� ----------------------------------------
  560. $sv = sizeof($this->values);
  561. if (sizeof($this->values) == 1) {
  562. $this->values[] = 0.00000000001;
  563. ++$sv;
  564. }
  565. $total = array_sum($this->values);
  566. $anglesum = $angle = Array(0);
  567. $i = 1;
  568. // ������ �����
  569. while ($i < $sv) {
  570. $part = $this->values[$i-1]/$total;
  571. $angle[$i] = floor($part*360);
  572. $anglesum[$i] = array_sum($angle);
  573. $i++;
  574. }
  575. $anglesum[] = $anglesum[0];
  576. // ������ ��������
  577. $diametr = $l_x1-10-10;
  578. // ������ ��������� ������ �������
  579. $circle_x = ($diametr/2)+10;
  580. $circle_y = $H/2-10;
  581. // �������� ��������,���� ������ �� ���������� �� ������
  582. if ($diametr > ($H*2)-10-10) {
  583. $diametr = ($H*2)-20-20-40;
  584. }
  585. // ����� ����
  586. for ($j = 20; $j > 0; $j--) {
  587. for ($i = 0;$i < sizeof($anglesum)-1; $i++) {
  588. ImageFilledArc($this->draw->res,$circle_x,$circle_y+$j,
  589. $diametr,$diametr/2,
  590. $anglesum[$i],$anglesum[$i+1],
  591. $this->draw->hex2color($this->shadows[$i]),IMG_ARC_PIE);
  592. }
  593. }
  594. // ����� �������� ���������
  595. for ($i = 0; $i < sizeof($anglesum)-1; $i++) {
  596. ImageFilledArc($this->draw->res,$circle_x,$circle_y,
  597. $diametr,$diametr/2,
  598. $anglesum[$i],$anglesum[$i+1],
  599. $this->draw->hex2color($this->colors[$i]),IMG_ARC_PIE);
  600. }
  601. }
  602. }