Advertisement
vovkakorben

Untitled

Jan 16th, 2022
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.17 KB | None | 0 0
  1. <?php
  2. error_reporting(E_ALL);
  3. $h = array();
  4. for ($i=0;$i<24;$i++)
  5. {
  6.     $h[$i] = rand(0,1000);
  7. }
  8.  
  9.  
  10. $w=550;
  11. $h=350;
  12. //DEFINE('MARGIN_LEFT',20);
  13. //DEFINE('MARGIN_TOP',5);
  14. //DEFINE('MARGIN_RIGHT',6);
  15. //DEFINE('MARGIN_BOTTOM',30);
  16. DEFINE('MARGIN_LEFT',100);
  17. DEFINE('MARGIN_TOP',100);
  18. DEFINE('MARGIN_RIGHT',100);
  19. DEFINE('MARGIN_BOTTOM',100);
  20. $l = MARGIN_LEFT;
  21. $r = $w - MARGIN_RIGHT;
  22. $t = MARGIN_TOP;
  23. $b = $h - MARGIN_BOTTOM;
  24. // setup
  25. $image = imagecreatetruecolor($w,$h);
  26. imagealphablending($image, true);
  27. // Allocate some colors
  28. $clr_bg =  imagecolorallocate($image, 0xdd, 0xdd, 0xdd);
  29. $clr_black    = imagecolorallocate($image, 0x00, 0x00, 0x00);
  30. $clr_gray    = imagecolorallocatealpha($image, 0xaa, 0xaa, 0xaa,0x10);
  31. $clr_blue    = imagecolorallocate($image, 0x49, 0xbd, 0xd6);    
  32. $clr_sky    = imagecolorallocate($image, 0x2e, 0x69, 0xd6);  
  33. // font
  34. $font = 'OpenSansCondensed-Light.ttf';
  35. $font_size = 12;
  36. // fill bg
  37. imagefilledrectangle($image,0,0,$w,$h,$clr_bg);
  38.  
  39. // 25% lines + text
  40. for ($i=0;$i<5;$i++)
  41. {
  42.     $y = $t + ($b-$t)/4*$i;
  43.     imageline($image,$l,$y,$r,$y,$clr_gray);
  44.     $txt = sprintf('%d%%',(4-$i)*25);
  45.  
  46.     $text_size = imagettftext ( $image , $font_size , 0 ,0 , 0 , $clr_black , $font ,$txt );
  47.     $tx = $l - $text_size[4]-3;
  48.     $ty = $y - $text_size[5]/2;
  49.     imagettftext($image,$font_size,0,$tx,$ty, $clr_black, $font, $txt);
  50. }
  51.  
  52.  
  53. // chart outline
  54. imagerectangle($image, $l, $t, $r, $b, $clr_black);
  55. /*
  56. // hour nums
  57. $rct_w =$w-MARGIN_LEFT-MARGIN_RIGHT;
  58. $rct_w_24 = $rct_w/24;
  59. for ($i=0;$i<24;$i++)
  60. {
  61. $txt = sprintf('%d',$i);
  62.  
  63. $text_size = imagettftext ( $image , $font_size , 0 ,0 , 0 , $clr_black , $font ,$txt );
  64. $tx = MARGIN_LEFT + $rct_w_24*$i + ($rct_w_24-$text_size[4])/2;
  65. $ty = $h-MARGIN_BOTTOM+5-$text_size[5];
  66. imagettftext($image,$font_size,0,$tx,$ty, $clr_black, $font, $txt);
  67.  
  68. imagefilledrectangle($image,
  69. MARGIN_LEFT+$rct_w_24*$i+1,$h-MARGIN_BOTTOM-($h[$i]),
  70. MARGIN_LEFT+$rct_w_24*($i+1)-1,$h-MARGIN_BOTTOM,
  71. $clr_blue);
  72. //imagerectangle($image, MARGIN_LEFT, MARGIN_TOP, $w-MARGIN_RIGHT, $h-MARGIN_BOTTOM, $clr_black);
  73. }
  74.  
  75. */
  76. // Flush the image
  77. header('Content-type: image/png');
  78. imagepng($image);
  79. imagedestroy($image);
  80.  
  81. ?>
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement