Advertisement
jargon

mk11 TILETEST.php

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