Advertisement
Guest User

Untitled

a guest
Apr 12th, 2014
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?
  2.         // @author rostok
  3.         // 2013-12-16 v1.0.1
  4.     // this uses imagemagick to explode spritesheet
  5.     // then it uses atlasmaker.jar https://bitbucket.org/grauw/atlasmaker/overview to create packed atlas
  6.     // it also parses index.json file to produce AS3 code that initializes all frames
  7.  
  8.     if (sizeof($argv)<4)
  9.     {
  10.             echo sizeof($argv);
  11.         echo "script.php file.png width height\noutput: file_atlas.png & file_atlas.as";
  12.         die();
  13.     }
  14.  
  15.     $f = $argv[1];
  16.     $fb = str_replace(".png","",$f);
  17.     $ws = $argv[2];
  18.     $hs = $argv[3];
  19.  
  20.     $dir = $fb."_atlas";
  21.     mkdir("tempdir1234");
  22.     echo("crop...");
  23.     exec("convert $f -crop $ws"."x$hs tempdir1234/c%04d.png");
  24.  
  25.  
  26. $man = "
  27. [
  28.    {
  29.        'name': '$dir',
  30.        'border': 0,
  31.        'maxSize': 8192,
  32.        'powersOfTwo': false,
  33.        'square': false,
  34.        'images': [ 'tempdir1234/*.png' ]
  35.    }
  36. ]";
  37.  
  38.     file_put_contents("manifest", $man);
  39.  
  40.     echo("atlas...");
  41.     exec("java -Xms1024m -jar ".dirname(__FILE__)."/atlasmaker-1.3-jar-with-dependencies.jar ./manifest .");
  42.     exec("move $dir\\atlas-0.png $dir.png");
  43.  
  44.     echo("parse...");
  45.     $js = json_decode (file_get_contents("$dir/index.json"));
  46.     $js = $js[0];
  47.     $js = $js->images;
  48.     $a = array();
  49.     while(list($k,$v)=each($js))
  50.     {
  51.             $x = $v->coordinates->x;
  52.             $y = $v->coordinates->y;
  53.             $w = $v->coordinates->width;
  54.             $h = $v->coordinates->height;
  55.             $xo = $v->xOffset;
  56.             $yo = $v->yOffset;
  57.             $fn = $v->path;
  58.             $fn = str_replace("tempdir1234/","",$fn);
  59.         $a[$fn] = "sprite.addFrameInfo($x,$y,$w,$h,$xo,$yo); // $fn\n";
  60.     }
  61.     ksort($a);
  62.     $out = "";
  63.     foreach ($a as $v) $out .= $v;
  64.  
  65.     file_put_contents($fb.".as", $out);
  66. //  exit();
  67.  
  68.     // cleanup
  69.     unlink("manifest");
  70.     exec("del /q tempdir1234\\c????.png");
  71.     exec("rd tempdir1234");
  72.     exec("rd /q /s $dir");
  73. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement