Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function regex_toc()
- {
- $nen = nen_ini();
- // table of contents filename pattern
- $toc_index = 0;
- //$toc_pattern = '/(?<prefix>____{4}|[a-z]{1}[a-z0-9_]{3})(?<suffix>____{4}|[a-z]{1}[a-z0-9_]{3})(?<ext>\.bmp)/';
- $toc_pattern =
- '/(?:.*)\.bmp/';
- $toc = fasttoc( 'tiles src data/rgb', array( '.bmp' ) );
- trk_echo2( 'toc', $toc );
- $toc_result = '';
- $tiles_replace = "$0\n";
- $toc_lines = array();
- $result = '';
- trk_echo2('image', $nen[ 'root' ]. 'tiles src data/rgb/');
- // loop through toc
- while(
- ($toc_index > count( $toc ) - 1)?false:preg_match(
- $toc_pattern,
- $toc[ $toc_index ],
- $toc_matches
- )
- )
- {
- /*
- // echo current toc filename
- $result .= '<h3>'. htmlentities( $toc[ $toc_index ] ). '</h3>';
- */
- // load current image document by toc index into page memory
- trk_echo2('image', $nen[ 'root' ]. 'tiles src data/rgb/'. $toc[ $toc_index ] );
- $image['rgb'] = imagecreatefrombmp( $nen[ 'root' ]. 'tiles src data/rgb/'. $toc[ $toc_index ] );
- $image['mask'] = imagecreatefrombmp( $nen[ 'root' ]. 'tiles src data/mask/'. $toc[ $toc_index ] );
- adhere_tiles( $image );
- file_put_contents( $nen[ 'root' ]. 'tiles out data/combo/'. $toc[ $toc_index ]. '.png', imagepng( $image['combo'] ) );
- // increment one table of contents file higher
- $toc_index++;
- }
- return $result;
- }
- function adhere_tiles( &$image = array() )
- {
- $nen = nen_ini();
- $result = '';
- //load tiles single layer png
- $width['rgb'] = imagesx($image['rgb']);
- $height['rgb'] = imagesy($image['rgb']);
- $width['mask'] = imagesx($image['mask']);
- $height['mask'] = imagesy($image['mask']);
- $width['combo'] = $width['rgb'];
- $height['combo'] = $height['rgb'];
- $image['combo'] = imagecreate($width['combo'], $height['combo']);
- // assign replacement (unused)
- //$tiles_replace = "$0\n";
- // create desination folder if it does not exist
- if( !is_dir( $nen[ 'root' ]. 'tiles out data' ) )
- {
- mkdir ( $nen[ 'root' ]. 'tiles out data' );
- }
- if( !is_dir( $nen[ 'root' ]. 'tiles out data/combo' ) )
- {
- mkdir ( $nen[ 'root' ]. 'tiles out data/combo' );
- }
- $col = 0;
- $row = 0;
- while($row < $height['combo'])
- {
- while($col < $width['combo'])
- {
- $pix['rgb']=imagecolorat($image['rgb'], $col, $row);
- $pix['mask']=imagecolorat($image['mask'], $col, $row);
- $pix['combo']=rand(0, 255);
- imagesetpixel($image['combo'], $col, $row, $pix['combo']);
- $col++;
- }
- $row++;
- }
- return $result;
- }
Add Comment
Please, Sign In to add comment