Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- // @author rostok
- // 2013-12-16 v1.0.1
- // this uses imagemagick to explode spritesheet
- // then it uses atlasmaker.jar https://bitbucket.org/grauw/atlasmaker/overview to create packed atlas
- // it also parses index.json file to produce AS3 code that initializes all frames
- if (sizeof($argv)<4)
- {
- echo sizeof($argv);
- echo "script.php file.png width height\noutput: file_atlas.png & file_atlas.as";
- die();
- }
- $f = $argv[1];
- $fb = str_replace(".png","",$f);
- $ws = $argv[2];
- $hs = $argv[3];
- $dir = $fb."_atlas";
- mkdir("tempdir1234");
- echo("crop...");
- exec("convert $f -crop $ws"."x$hs tempdir1234/c%04d.png");
- $man = "
- [
- {
- 'name': '$dir',
- 'border': 0,
- 'maxSize': 8192,
- 'powersOfTwo': false,
- 'square': false,
- 'images': [ 'tempdir1234/*.png' ]
- }
- ]";
- file_put_contents("manifest", $man);
- echo("atlas...");
- exec("java -Xms1024m -jar ".dirname(__FILE__)."/atlasmaker-1.3-jar-with-dependencies.jar ./manifest .");
- exec("move $dir\\atlas-0.png $dir.png");
- echo("parse...");
- $js = json_decode (file_get_contents("$dir/index.json"));
- $js = $js[0];
- $js = $js->images;
- $a = array();
- while(list($k,$v)=each($js))
- {
- $x = $v->coordinates->x;
- $y = $v->coordinates->y;
- $w = $v->coordinates->width;
- $h = $v->coordinates->height;
- $xo = $v->xOffset;
- $yo = $v->yOffset;
- $fn = $v->path;
- $fn = str_replace("tempdir1234/","",$fn);
- $a[$fn] = "sprite.addFrameInfo($x,$y,$w,$h,$xo,$yo); // $fn\n";
- }
- ksort($a);
- $out = "";
- foreach ($a as $v) $out .= $v;
- file_put_contents($fb.".as", $out);
- // exit();
- // cleanup
- unlink("manifest");
- exec("del /q tempdir1234\\c????.png");
- exec("rd tempdir1234");
- exec("rd /q /s $dir");
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement