Decompressing Tiled TMX file contents with PHP

webpro_ir

New Member
I am having problems extracting the layer contents from a .tmx (Tiled) file.I would like to get the complete uncompressed data in PHP and make a little image of it.Getting the header information like width, height and so on is no problem - SimpleXML is doing its job there. But somehow decompressing of the tile layer is not working.The data itself is stored as a base64 and gzip encoded string (sth like \[code\]H4sIAAAAAAAAC+3bORKAIBQEUVzuf2YTTSwEA/gL00EnJvJQsAjcSyk7EU3v+Jn3OI\[/code\]) but I am having problems even getting the base64 decoded code (it just gives me wierd characters and when i reopened the map in tiled and saved it as "base64 uncompressed" the result was just an empty string - not using gzip decompressing of course).I already searched through the web and saw how the data is exactly compressed (Github article). It seems like i have to use the \[code\]gzinflate()\[/code\] command instead of all the others (e.g. gzuncompress), but this is also not working for me.The code i have now is the following:\[code\]<?php // Get the raw xml data $map_xml = new SimpleXML(file_get_contents("map.tmx")); $data = http://stackoverflow.com/questions/10613996/$map_xml["layer"][0]["data"]["@content"]; // I would make a loop here $content =gzinflate(base64_decode($map_content)); // gives me and error var_dump($data); // results in nothing?>\[/code\]After some more research I found out that I should use a zlib filter (php.net article).Now I was really confused I don't know what I should pick - I asked google again and got the following: Compressing with Java Decompressing with PHP. According to the answer I have to crop our the header before using the base64 and gzip methods.Now my questions: Do I have to crop out the header before? If yes, how do I do that? If not, how can I get the uncompressed data then?I really hope that someone can help me in here!
 
Back
Top