<?php 

/*----------------------------------------------------------------------------*/
/* Tylor - script to create a tile based map
   Author: Sebastian Schaetz - echelon.blog@gmail.com
   Web: http://www.soa-world.de/echelon                                       */
/*----------------------------------------------------------------------------*/

  
$tilewidth 18;                                              // width of tile
  
$tileheight 13;                                            // height of tile
  
$imgwidth $tilewidth 100;                                // width of image
  
$imgheight $tileheight/200;                           // height of image
  
$numtiles 6;                                    // number of tiles available
  
  
$offset_layers 4;                   // some values needed to place the tiles
  
$offset_x 16;
  
$offset_y 4;
  
$indent_x 8;
  
  
$data = array();
  
$handle fopen("\\path\\to\\csv\\file.csv""r");
  
$i 0;
  while ((
$data[$i] = fgetcsv($handle1000",")) !== FALSE)
    
$i++;
    
  
$im imagecreate($imgwidth$imgheight);               // create target image
  
$black imagecolorallocate($im000);  
  
imagefill($im$imgwidth$imgheight$black);
  
imagecolortransparent($im$black);
  
  
$tiles = array();
  for(
$t=0$t<$numtiles$t++)                                    // load tiles
    
$tiles[$t] = imagecreatefromgif($t '.gif'); 
  
  
$offset 0;
  for(
$t=0$t<$numtiles$t++)                           // draw tiles on image
  
{
    for(
$y=0$y<count($data); $y++)
    { 
      
$indent = ($y%2) * $indent_x;
      for(
$x=0$x<count($data[0]); $x++)
        if(
$data[$y][$x] >= $t)
          
imagecopymerge($im$tiles[$t], $x*$offset_x $indent
            
$y*$offset_y $offset00$tilewidth$tileheight100);
    }
    
$offset += $offset_layers;
  }
  
  
header("Content-type: image/gif");                             // output image
  
imagegif($im);
  
imagedestroy($im);
  
?>