Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(0);
- function LoadPNG($imgname)
- {
- /* Attempt to open */
- $im = @imageCreateFromPng($imgname);
- /* See if it failed */
- if(!$im || !$_POST['score'] || !$_POST['usr'])
- {
- /* Create a black image */
- $im = imagecreatetruecolor(150, 30);
- $bgc = imagecolorallocate($im, 124, 55, 22);
- $tc = imagecolorallocate($im, 0, 0, 0);
- imagefilledrectangle($im, 10, 20, 60, 60, $bgc);
- /* Output an error message */
- imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc);
- } else {
- $red = imagecolorallocate($im, 255, 0, 0);
- $tc = imagecolorallocate($im, 0, 0, 0);
- $white = imagecolorallocate($im, 255, 255, 255);
- imageAlphaBlending($im, true);
- imageSaveAlpha($im, true);
- $box_size = 24;
- $total_boxes_to_draw = $_POST['score'];
- $gap = 2; /*1 px gap between boxes both ways up and down*/
- $gap_vertical = 2;
- $cols = 5;
- $rows = 5;
- /*draw first box at..*/
- switch($_POST['usr']){
- case "dc":
- $origin_x = 207;
- $origin_y = 195;
- break;
- case "pd":
- $origin_x = 40;
- $origin_y = 195;
- break;
- default:
- $origin_x = 40;
- $origin_y = 195;
- }
- $total_boxes_to_draw = $total_boxes_to_draw - 1;
- $x=0;
- $current_col = 0;
- $current_row = 0;
- $last_block_x = $origin_x;
- $last_block_y = $origin_y;
- while($x <= $total_boxes_to_draw)
- {
- if($current_col >= $cols)
- {
- $current_col = 0;
- $current_row = $current_row + 1;
- $last_block_x = $origin_x;
- $last_block_y = $origin_y + $current_row * $box_size + $gap_vertical;
- }
- /*hoz coord 1*/
- $left_wall_of_box_x = ( $current_col * $box_size ) + $origin_x ;
- if($last_block_x != $origin_x){
- $left_wall_of_box_x = $last_block_x + $gap;
- }
- /*verticals coord 1*/
- $left_wall_of_box_y = ( $current_row * $box_size ) + $origin_y;
- $right_wall_x = $left_wall_of_box_x + $box_size ;
- $right_wall_y = $left_wall_of_box_y + $box_size;
- /*for debug*/
- // imagestring($im, 1, 5, $x * 10, $left_wall_of_box_x . ",". $left_wall_of_box_y, $white);
- imagestring($im, 1, 5, $x * 10, "this block bottom edge: ". $right_wall_y, $white);
- imagefilledrectangle($im, $left_wall_of_box_x, $left_wall_of_box_y, $right_wall_x, $right_wall_y, $red);
- $last_block_x = $right_wall_x;
- $last_block_y = $left_wall_of_box_y;
- $x++;
- $current_col++;
- }
- }
- return $im;
- }
- /*save to file*/
- $foxname = 'score_card_1.png';
- $img = LoadPNG($foxname);
- imagepng($img, $foxname);
- /*free memory*/
- imagedestroy($img);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement