rhoula

Untitled

Jan 17th, 2013
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. <?php
  2.  
  3. // This array of values is just here for the example.
  4.  
  5. $values = array("23","32","35","57","12",
  6. "3","36","54","32","15",
  7. "43","24","30");
  8.  
  9. // Get the total number of columns we are going to plot
  10.  
  11. $columns = count($values);
  12.  
  13. // Get the height and width of the final image
  14.  
  15. $width = 300;
  16. $height = 200;
  17.  
  18. // Set the amount of space between each column
  19.  
  20. $padding = 5;
  21.  
  22. // Get the width of 1 column
  23.  
  24. $column_width = $width / $columns ;
  25.  
  26. // Generate the image variables
  27.  
  28. $im = imagecreate($width,$height);
  29. $gray = imagecolorallocate ($im,0xcc,0xcc,0xcc);
  30. $gray_lite = imagecolorallocate ($im,0xee,0xee,0xee);
  31. $gray_dark = imagecolorallocate ($im,0x7f,0x7f,0x7f);
  32. $white = imagecolorallocate ($im,0xff,0xff,0xff);
  33.  
  34. // Fill in the background of the image
  35.  
  36. imagefilledrectangle($im,0,0,$width,$height,$white);
  37.  
  38. $maxv = 0;
  39.  
  40. // Calculate the maximum value we are going to plot
  41.  
  42. for($i=0;$i<$columns;$i++)$maxv = max($values[$i],$maxv);
  43.  
  44. // Now plot each column
  45.  
  46. for($i=0;$i<$columns;$i++)
  47. {
  48. $column_height = ($height / 100) * (( $values[$i] / $maxv) *100);
  49.  
  50. $x1 = $i*$column_width;
  51. $y1 = $height-$column_height;
  52. $x2 = (($i+1)*$column_width)-$padding;
  53. $y2 = $height;
  54.  
  55. imagefilledrectangle($im,$x1,$y1,$x2,$y2,$gray);
  56.  
  57. // This part is just for 3D effect
  58.  
  59. imageline($im,$x1,$y1,$x1,$y2,$gray_lite);
  60. imageline($im,$x1,$y2,$x2,$y2,$gray_lite);
  61. imageline($im,$x2,$y1,$x2,$y2,$gray_dark);
  62.  
  63. }
  64.  
  65. // Send the PNG header information. Replace for JPEG or GIF or whatever
  66.  
  67. header ("Content-type: image/png");
  68. imagepng($im);
  69. ?>
Advertisement
Add Comment
Please, Sign In to add comment