Advertisement
jargon

Roe Builder mk11 TILESTEST

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