Advertisement
jargon

Roe Builder mk11 TILESTEST 100% OK

Oct 10th, 2021
1,625
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.52 KB | None | 0 0
  1. <?php
  2.  
  3. $filename = 'dtbykick';
  4. $alpha = 127;
  5.  
  6. combo($filename, $alpha);
  7.  
  8. echo '<html><head><title>'. $filename. '</title></head><body style="background-color:springgreen;"><h3>'. htmlentities( $filename ). '</h3><img src="./tiles src data/rgb/'. $filename. '.bmp"><img src="./tiles src data/mask/'. $filename. '.bmp"><img src="./tiles out data/combo/'. $filename. '.png"></body></html>';
  9.  
  10. function combo($filename='dtbykick', $alpha = 127 )
  11. {
  12.     //$filename='dtbykick';
  13.    
  14.     $image[ 'rgb' ] = imagecreatefrombmp( $_SERVER['DOCUMENT_ROOT']. '/Roe XAMPP Builder/tiles src data/rgb/'.$filename.'.bmp' );
  15.    
  16.     $image[ 'mask' ] = imagecreatefrombmp( $_SERVER['DOCUMENT_ROOT']. '/Roe XAMPP Builder/tiles src data/mask/'.$filename.'.bmp' );
  17.    
  18.     //imagepng( $image['combo'],'./'.$filename.'-combo.png' );
  19.    
  20.     $image [ 'combo' ] = imagecreatetruecolor( imagesx( $image[ 'rgb' ] ), imagesy( $image[ 'rgb' ] ) );
  21.  
  22.     imagesavealpha( $image [ 'combo' ], true);
  23.  
  24.     $trans_colour = imagecolorallocatealpha( $image [ 'combo' ], 0, 0, 0, 127 );
  25.     imagefill( $image [ 'combo' ], 0, 0, $trans_colour );
  26.    
  27.     $width = imagesx( $image[ 'combo' ] );
  28.     $height = imagesy( $image[ 'combo' ] );
  29.  
  30.     //loop through width and height of source image
  31.     $row=0;
  32.     while( $row < $height )
  33.     {
  34.         $col=0;
  35.         while( $col < $width )
  36.         {
  37.            
  38.             //get color in image $image[ 'mask' ] at pixel ($col, $row)
  39.            
  40.             $pix[ 'mask' ] = imagecolorat( $image[ 'mask' ], $col, $row );
  41.  
  42.             //get color in image $image[ 'rgb' ] at pixel ($col, $row)
  43.            
  44.             $pix[ 'rgb' ] = imagecolorat( $image[ 'rgb' ], $col, $row );
  45.            
  46.             //if pixel in $image['mask'] at ($cow, $row) is white:
  47.                  
  48.             if ( ( $pix[ 'mask' ] & 0xFFFFFF ) === 0xFFFFFF )
  49.             {
  50.                 //set pixel based on Mask layer's ($col, $row) as fully transparent
  51.                 $pix[ 'combo' ] = alphaColor("FFFFFF", $alpha );
  52.             }
  53.             //else
  54.             else
  55.             {              
  56.                 //set pixel based on RGB layer's ($col, $row) with full opacity
  57.                 $pix[ 'combo' ] = $pix[ 'rgb' ];           
  58.             }
  59.            
  60.             //assign pixel data to $image['combo'] at ($col , $row)
  61.             imagesetpixel( $image[ 'combo' ], $col, $row, $pix[ 'combo' ] );
  62.            
  63.             if( $col === $width - 1 )
  64.             {
  65.                 break;
  66.             }  
  67.             $col++;
  68.         }
  69.         if( $row === $height - 1 )
  70.         {
  71.             break;
  72.         }
  73.         $row++;
  74.     }
  75.    
  76.     //save resulting image as new file 
  77.     imagepng( $image[ 'combo' ], $_SERVER['DOCUMENT_ROOT']. '/Roe XAMPP Builder/tiles out data/combo/'. $filename. '.png' );
  78. }
  79.  
  80. function alphaColor($hexColor,$alpha)
  81. {
  82.         return bindec(decbin($alpha).decbin(hexdec($hexColor)));
  83. }
  84.  
  85. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement