jargon

GD Image Palette

Oct 9th, 2021 (edited)
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.54 KB | None | 0 0
  1. function regex_toc()
  2. {
  3.     $nen = nen_ini();
  4.    
  5.     // table of contents filename pattern
  6.     $toc_index = 0;
  7.    
  8.     //$toc_pattern = '/(?<prefix>____{4}|[a-z]{1}[a-z0-9_]{3})(?<suffix>____{4}|[a-z]{1}[a-z0-9_]{3})(?<ext>\.bmp)/';
  9.    
  10.     $toc_pattern =
  11.     '/(?:.*)\.bmp/';
  12.    
  13.     $toc = fasttoc( 'tiles src data/rgb', array( '.bmp' ) );
  14.  
  15.     trk_echo2( 'toc', $toc );
  16.  
  17.     $toc_result = '';
  18.  
  19.     $tiles_replace = "$0\n";
  20.    
  21.     $toc_lines = array();
  22.    
  23.     $result = '';
  24.  
  25.     trk_echo2('image', $nen[ 'root' ]. 'tiles src data/rgb/');
  26.  
  27.    
  28.     // loop through toc
  29.     while(
  30.         ($toc_index > count( $toc ) - 1)?false:preg_match(
  31.         $toc_pattern,
  32.         $toc[ $toc_index ],
  33.         $toc_matches
  34.         )
  35.     )
  36.     {      
  37.         /*
  38.         // echo current toc filename
  39.         $result .= '<h3>'. htmlentities( $toc[ $toc_index ] ). '</h3>';
  40.         */
  41.        
  42.         // load current image document by toc index into page memory
  43.        
  44.         trk_echo2('image', $nen[ 'root' ]. 'tiles src data/rgb/'. $toc[ $toc_index ] );
  45.  
  46.         $image['rgb'] = imagecreatefrombmp( $nen[ 'root' ]. 'tiles src data/rgb/'. $toc[ $toc_index ] );
  47.         $image['mask'] = imagecreatefrombmp( $nen[ 'root' ]. 'tiles src data/mask/'. $toc[ $toc_index ] );
  48.                
  49.         adhere_tiles( $image );
  50.        
  51.         file_put_contents( $nen[ 'root' ]. 'tiles out data/combo/'. $toc[ $toc_index ]. '.png', imagepng( $image['combo'] ) );
  52.  
  53.         // increment one table of contents file higher
  54.         $toc_index++;      
  55.        
  56.     }
  57.    
  58.     return $result;
  59.    
  60. }
  61.  
  62. function adhere_tiles( &$image = array() )
  63. {
  64.     $nen = nen_ini();
  65.     $result = '';
  66.    
  67.     //load tiles single layer png
  68.    
  69.     $width['rgb']  = imagesx($image['rgb']);
  70.     $height['rgb']  = imagesy($image['rgb']);
  71.  
  72.     $width['mask']  = imagesx($image['mask']);
  73.     $height['mask']  = imagesy($image['mask']);
  74.  
  75.     $width['combo']  = $width['rgb'];
  76.     $height['combo']  = $height['rgb'];
  77.    
  78.     $image['combo'] = imagecreate($width['combo'], $height['combo']);
  79.      
  80.     // assign replacement (unused)
  81.     //$tiles_replace = "$0\n";
  82.    
  83.     // create desination folder if it does not exist
  84.  
  85.     if( !is_dir( $nen[ 'root' ]. 'tiles out data' ) )
  86.     {
  87.         mkdir ( $nen[ 'root' ]. 'tiles out data' );
  88.     }
  89.  
  90.     if( !is_dir( $nen[ 'root' ]. 'tiles out data/combo' ) )
  91.     {
  92.         mkdir ( $nen[ 'root' ]. 'tiles out data/combo' );
  93.     }
  94.    
  95.     $col = 0;
  96.     $row = 0;
  97.     while($row < $height['combo'])
  98.     {
  99.         while($col < $width['combo'])
  100.         {
  101.             $pix['rgb']=imagecolorat($image['rgb'], $col, $row);
  102.            
  103.             $pix['mask']=imagecolorat($image['mask'], $col, $row);
  104.            
  105.             $pix['combo']=rand(0, 255);
  106.            
  107.             imagesetpixel($image['combo'], $col, $row, $pix['combo']);
  108.             $col++;
  109.         }
  110.         $row++;
  111.     }
  112.            
  113.     return $result;
  114.    
  115. }
  116.  
Add Comment
Please, Sign In to add comment