Created
June 9, 2019 21:01
-
-
Save p0358/b9cf19c3f58ee3bdc94d1a7afcd9a070 to your computer and use it in GitHub Desktop.
Flappy Bird's atlas.png/txt simple extractor. — Extracts assets from atlas.png into separate files based on assets definitions from atlas.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$atlas_file = file_get_contents('atlas.txt'); | |
// Hardcoded source image size | |
$x = 1024; | |
$y = 1024; | |
@mkdir('out'); | |
// https://www.php.net/manual/en/imagick.writeimage.php | |
// https://www.php.net/manual/en/imagick.cropimage.php | |
function cropImage($imagePath, $destination, $width, $height, $startX, $startY) { | |
$imagick = new \Imagick(realpath($imagePath)); | |
$imagick->cropImage($width, $height, $startX, $startY); | |
$imagick->writeImage($destination); | |
} | |
foreach (explode("\n", $atlas_file) as $line) { | |
$line = trim($line); | |
if (!empty($line)) { | |
$parts = explode(' ', $line); | |
cropImage('atlas.png', 'out/' . $parts[0] . '.png', $parts[1], $parts[2], $parts[3]*$x, $parts[4]*$y); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment