Advertisement
jargon

Roe Builder mk11 TILESTEST

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