Advertisement
Guest User

codebinn

a guest
May 31st, 2013
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. <?php
  2. error_reporting(0);
  3.  
  4.  
  5. function LoadPNG($imgname)
  6. {
  7. /* Attempt to open */
  8. $im = @imageCreateFromPng($imgname);
  9.  
  10. /* See if it failed */
  11. if(!$im || !$_POST['score'] || !$_POST['usr'])
  12. {
  13. /* Create a black image */
  14. $im = imagecreatetruecolor(150, 30);
  15. $bgc = imagecolorallocate($im, 124, 55, 22);
  16. $tc = imagecolorallocate($im, 0, 0, 0);
  17.  
  18. imagefilledrectangle($im, 10, 20, 60, 60, $bgc);
  19.  
  20. /* Output an error message */
  21. imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc);
  22.  
  23. } else {
  24.  
  25. $red = imagecolorallocate($im, 255, 0, 0);
  26. $tc = imagecolorallocate($im, 0, 0, 0);
  27. $white = imagecolorallocate($im, 255, 255, 255);
  28.  
  29. imageAlphaBlending($im, true);
  30. imageSaveAlpha($im, true);
  31.  
  32. $box_size = 24;
  33. $total_boxes_to_draw = $_POST['score'];
  34. $gap = 2; /*1 px gap between boxes both ways up and down*/
  35. $gap_vertical = 2;
  36.  
  37. $cols = 5;
  38. $rows = 5;
  39.  
  40. /*draw first box at..*/
  41. switch($_POST['usr']){
  42. case "dc":
  43. $origin_x = 207;
  44. $origin_y = 195;
  45. break;
  46.  
  47. case "pd":
  48. $origin_x = 40;
  49. $origin_y = 195;
  50.  
  51. break;
  52. default:
  53. $origin_x = 40;
  54. $origin_y = 195;
  55.  
  56. }
  57.  
  58. $total_boxes_to_draw = $total_boxes_to_draw - 1;
  59. $x=0;
  60. $current_col = 0;
  61. $current_row = 0;
  62. $last_block_x = $origin_x;
  63. $last_block_y = $origin_y;
  64. while($x <= $total_boxes_to_draw)
  65. {
  66.  
  67.  
  68. if($current_col >= $cols)
  69. {
  70. $current_col = 0;
  71. $current_row = $current_row + 1;
  72. $last_block_x = $origin_x;
  73. $last_block_y = $origin_y + $current_row * $box_size + $gap_vertical;
  74. }
  75.  
  76. /*hoz coord 1*/
  77.  
  78. $left_wall_of_box_x = ( $current_col * $box_size ) + $origin_x ;
  79.  
  80.  
  81. if($last_block_x != $origin_x){
  82.  
  83. $left_wall_of_box_x = $last_block_x + $gap;
  84.  
  85. }
  86.  
  87. /*verticals coord 1*/
  88. $left_wall_of_box_y = ( $current_row * $box_size ) + $origin_y;
  89.  
  90.  
  91.  
  92.  
  93. $right_wall_x = $left_wall_of_box_x + $box_size ;
  94. $right_wall_y = $left_wall_of_box_y + $box_size;
  95.  
  96.  
  97.  
  98.  
  99. /*for debug*/
  100. // imagestring($im, 1, 5, $x * 10, $left_wall_of_box_x . ",". $left_wall_of_box_y, $white);
  101. imagestring($im, 1, 5, $x * 10, "this block bottom edge: ". $right_wall_y, $white);
  102.  
  103. imagefilledrectangle($im, $left_wall_of_box_x, $left_wall_of_box_y, $right_wall_x, $right_wall_y, $red);
  104.  
  105.  
  106. $last_block_x = $right_wall_x;
  107. $last_block_y = $left_wall_of_box_y;
  108.  
  109.  
  110.  
  111. $x++;
  112. $current_col++;
  113.  
  114. }
  115.  
  116.  
  117.  
  118.  
  119.  
  120. }
  121.  
  122. return $im;
  123. }
  124.  
  125.  
  126. /*save to file*/
  127. $foxname = 'score_card_1.png';
  128. $img = LoadPNG($foxname);
  129. imagepng($img, $foxname);
  130.  
  131.  
  132. /*free memory*/
  133. imagedestroy($img);
  134.  
  135.  
  136.  
  137. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement