From abcd7298cd191c5ea79d14bde0b31c943eee9d4a Mon Sep 17 00:00:00 2001 From: noodlebox Date: Sat, 10 Sep 2016 17:35:30 -0500 Subject: [PATCH 1/2] Use montage instead of composite for massive speedup --- build/build_image.php | 118 ++++++++++++++---------------------------- 1 file changed, 38 insertions(+), 80 deletions(-) diff --git a/build/build_image.php b/build/build_image.php index 7806927c33..f4ee148b9c 100644 --- a/build/build_image.php +++ b/build/build_image.php @@ -1,11 +1,9 @@ array("pipe", "r") + ); - $dst = $GLOBALS['dir']."/../sheet_{$type}_{$img_w}_col{$i}.png"; + $pipes = array(); - echo shell_exec("convert -size {$img_w}x{$ph} xc:none {$dst}"); + # chdir into parent directory first + $cwd = __DIR__.'/..'; - foreach ($comp as $row){ - if ($row[0] != $i) continue; + $res = proc_open($cmd, $fd_spec, $pipes, $cwd); - $px = 0; - $py = $row[1] * $img_w; - - $path = $GLOBALS['dir'].'/../'.$row[2]; - if (file_exists($path)){ - - echo shell_exec("composite -geometry +{$px}+{$py} {$path} {$dst} {$dst}"); - echo '.'; - }else{ - echo "(not found: $src)"; - } + # Write out each filename + foreach ($comp as $index => $file){ + if ($file !== null){ + fwrite($pipes[0], "{$file}\n"); + echo '.'; + }else{ + fwrite($pipes[0], "null:\n"); + echo ' '; } - echo " OK\n"; + if ($index % $size == $size - 1){ + echo "\n"; + } } + fclose($pipes[0]); - # - # merge the strips - # - - echo "merging ... "; - - $dst = $GLOBALS['dir']."/../sheet_{$type}_{$img_w}.png"; - - echo shell_exec("convert -size {$pw}x{$ph} xc:none {$dst}"); - - for ($i=0; $i<$mp; $i++){ - $src = $GLOBALS['dir']."/../sheet_{$type}_{$img_w}_col{$i}.png"; - - $px = $i * $img_w; - $py = 0; - - echo shell_exec("composite -geometry +{$px}+{$py} {$src} {$dst} {$dst}"); - echo '.'; - - unlink($src); + if (proc_close($res) > 0) { + echo "Something went wrong\n\n"; + return; } - echo " OK\n"; - - echo "Optimizing sheet ... "; - echo shell_exec("convert {$dst} png32:{$dst}"); echo "DONE\n\n"; } - - function composite($sheet_x, $sheet_y, $img_w, $src, $dst){ - - $px = $sheet_x * $img_w; - $py = $sheet_y * $img_w; - - $path = $GLOBALS['dir'].'/../'.$src; - if (file_exists($path)){ - - echo shell_exec("composite -geometry +{$px}+{$py} {$path} {$dst} {$dst}"); - echo '.'; - }else{ - echo "(not found: $src)"; - } - } From 99d78fcd7b317a9cdb393d8c84fdee353f81e584 Mon Sep 17 00:00:00 2001 From: noodlebox Date: Sat, 10 Sep 2016 17:42:01 -0500 Subject: [PATCH 2/2] Update README, now that build_image is no longer slow --- build/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/README.md b/build/README.md index 845c219e66..a8f6312382 100644 --- a/build/README.md +++ b/build/README.md @@ -21,7 +21,7 @@ You can rebuild by following these steps: # Rebuild positions and make the master spritesheets # (This step requires ImageMagick or GraphicsMagick) - php build_image.php # this is slow! + php build_image.php php build_sheets.php # create quantized sheets and optimize them all (_very_ slow)