Advertisement
Guest User

game_rollarcoaster.php

a guest
Sep 3rd, 2019
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.25 KB | None | 0 0
  1. <?php
  2. $width=0;
  3. $height=0;
  4. $data="";
  5.  
  6. if(isset($_POST["img_height"]))
  7. {
  8.     if(is_numeric($_POST["img_height"]))
  9.     {
  10.         $height=(int)$_POST["img_height"];
  11.     }
  12.     else
  13.     {
  14.         echo("img_height is NaN");
  15.         exit();
  16.     }
  17. }
  18. else
  19. {
  20.     echo("img_height is undefined");
  21.     exit();
  22. }
  23.  
  24. if(isset($_POST["img_width"]))
  25. {
  26.     if(is_numeric($_POST["img_width"]))
  27.     {
  28.         $width=(int)$_POST["img_width"];
  29.     }
  30.     else
  31.     {
  32.         echo("img_width is NaN");
  33.         exit();
  34.     }
  35. }
  36. else
  37. {
  38.     echo("img_width is undefined");
  39.     exit();
  40. }
  41. if(isset($_POST["img_data"]))
  42. {
  43.     $data=$_POST["img_data"];
  44. }
  45. else
  46. {
  47.     echo("img_data is undefined");
  48.     exit();
  49. }
  50.  
  51. $img = imagecreatetruecolor($width,$height);
  52.  
  53. $x = 0;
  54. $y = 0;
  55. $i = 0;
  56.  
  57. while($x < $width)
  58. {
  59.   $y = 0;
  60.   while($y < $height)
  61.   {
  62.     $red = hexdec(substr($data,$i,2));
  63.     $i += 2;
  64.    
  65.     $green = hexdec(substr($data,$i,2));
  66.     $i += 2;
  67.    
  68.     $blue = hexdec(substr($data,$i,2));
  69.     $i += 2;
  70.    
  71.     $color = imagecolorallocate($img,$red,$green,$blue);
  72.     imagesetpixel($img,$x,$y,$color);
  73.    
  74.      $y++;
  75.   }
  76.   $x++;
  77. }
  78.  
  79. header('Content-Type: image/png');
  80.  
  81. //chrome doesnt like saving dynamically generated images so..
  82. header('Content-Disposition: attachment; filename="'.md5(rand(0,256)).'.png"');
  83.  
  84. imagepng($img);
  85. imagedestroy($img);
  86. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement