$error)
{
if ($error == UPLOAD_ERR_OK )
{
$tmp_name = $_FILES["uploadfiles"]["tmp_name"][$key];
$name = $_FILES["uploadfiles"]["name"][$key];
$file = "terrain/$time/$name";
move_uploaded_file($tmp_name, $file);
$uploadfiles[] = $file;
}
}
$i = 0;
$b = 8*2;
$d = 2048;
$e = $d / 4;
$f = $e-$b-$b;
$img = imagecreatetruecolor($d, $d) or die("Cannot Initialize new GD image stream");
foreach ($uploadfiles as $filename)
{
$x = $e*($i % 4);
$y = $e*floor($i / 4);
++$i;
$partimg_orig = imagecreatefrompng($filename) or die("failed to load part".$filename);
$partimg = imagecreatetruecolor($f,$f) or die("Cannot Initialize new GD image stream");
imagecopyresized($partimg,$partimg_orig,0,0,0,0,$f,$f,$terrain_size,$terrain_size);
// left border
MyDraw($img,$partimg, $x+$b,$y+$b, $x ,$y , $b,$b);
MyDraw($img,$partimg, $x+$b,$y+$b, $x ,$y+$b , $b,$f);
MyDraw($img,$partimg, $x+$b,$y+$b, $x ,$y+$b+$f , $b,$b);
// right border
MyDraw($img,$partimg, $x+$b,$y+$b, $x+$b+$f ,$y , $b,$b);
MyDraw($img,$partimg, $x+$b,$y+$b, $x+$b+$f ,$y+$b , $b,$f);
MyDraw($img,$partimg, $x+$b,$y+$b, $x+$b+$f ,$y+$b+$f , $b,$b);
// top and bottom
MyDraw($img,$partimg, $x+$b,$y+$b, $x+$b ,$y , $f,$b);
MyDraw($img,$partimg, $x+$b,$y+$b, $x+$b ,$y+$b+$f , $f,$b);
// center part
MyDraw($img,$partimg, $x+$b,$y+$b, $x+$b,$y+$b, $f,$f);
imagedestroy($partimg);
imagedestroy($partimg_orig);
}
$working_img = "terrain/$time/terrain_tex_atlas.png";
imagepng($img, $working_img);
imagedestroy($img);
$image_src = "";
ksort($_POST['resolution'], SORT_ASC);
foreach( $_POST['resolution'] AS $key => $out_res )
{
$image_src .= "{$out_res}x{$out_res}
";
$copyimg = imagecreatefrompng($working_img) or die("Cannot Initialize new GD image stream");
$resizeimg = imagecreatetruecolor($out_res,$out_res) or die("Cannot Initialize new GD image stream");
imagecopyresized($resizeimg,$copyimg,0,0,0,0,$out_res,$out_res,$d,$d);
imagepng($resizeimg, "terrain/$time/terrain_tex_atlas_$out_res.png");
$image_src .= "
";
imagedestroy($resizeimg);
imagedestroy($copyimg);
}
// Cleanup
foreach( $uploadfiles AS $filename )
@unlink( $filename );
@unlink($working_img);
@rmdir("terrain/$time");
print $image_src;
}
else
{
$buttons = "Resolutions
";
foreach( $resolutions AS $key => $res )
{
$buttons .= "";
}
$input_files = "Texture Files
";
for( $x = 0; $x < 4; $x++ )
{
for( $y = 0; $y < 4; $y++ )
{
$input_files .= " ";
}
$input_files .= "
";
}
$submit_button = "";
print "