I thought I would just share my PHP spritesheet stitcher script here:
Code: Select all
<html><head><title>Transcendence Frame Stitcher</title></head><body><pre>
<?php
define('SOURCE_PATH', 'frames');
define('SOURCE_FILENAME_BASE', 'enter_file_name_here'); // expects file names written as: ship0000.png
define('OUTPUT_PATH', '.');
define('OUTPUT_FILENAME', SOURCE_FILENAME_BASE);
$imgSources = array();
if ($dh = opendir(SOURCE_PATH)) {
while (false !== ($node = readdir($dh))) {
if (substr($node, 0, strlen(SOURCE_FILENAME_BASE)) <> SOURCE_FILENAME_BASE) {
continue;
}
$imgSources[] = $node;
}
}
$frameCount = count($imgSources);
echo "Stitching $frameCount frame(s)...";
$imgOut = null;
$imgOutMask = null;
foreach ($imgSources as $frame) {
$imgSource = imagecreatefrompng(SOURCE_PATH.'/'.$frame);
if (null === $imgOut) {
$width = imagesx($imgSource);
$height = imagesy($imgSource);
$imgOut = imagecreatetruecolor($width, $height * $frameCount);
$imgOutMask = imagecreatetruecolor($width, $height * $frameCount);
imagefill($imgOutMask, 0, 0, imagecolorallocate($imgOutMask, 0, 0, 0));
$offset = 0;
} else {
$offset += $height;
}
flush();
for ($x = 0; $x < $width; $x++) {
for ($y = 0; $y < $height; $y++) {
$pixel = imagecolorsforindex($imgSource, imagecolorat($imgSource, $x, $y));
$alpha = 255 - $pixel['alpha'] * 2;
imagesetpixel($imgOutMask, $x, $offset + $y, imagecolorallocate($imgOutMask, $alpha, $alpha, $alpha));
}
}
imagecopy($imgOut, $imgSource, 0, $offset, 0, 0, $width, $height);
imagedestroy($imgSource);
}
echo " done\n";
imagejpeg($imgOut, OUTPUT_PATH.'/'.OUTPUT_FILENAME.'.jpg', 95);
imagepng($imgOutMask, OUTPUT_PATH.'/'.OUTPUT_FILENAME.'Mask.png', 0);
imagedestroy($imgOut);
imagedestroy($imgOutMask);
echo '<img src="'.OUTPUT_PATH.'/'.OUTPUT_FILENAME.'.jpg?cd='.time().'" width="'.$width.'" height="'.($height * $frameCount).'" alt="" style="padding:0 2px;"/>';
echo '<img src="'.OUTPUT_PATH.'/'.OUTPUT_FILENAME.'Mask.png?cd='.time().'" width="'.$width.'" height="'.($height * $frameCount).'" alt="" style="padding:0 2px;"/>';
?></pre><body></html>
It was never written with user-friendliness in mind, it
only supports 32-bit (=rgb+alpha) png images, requires source frames to be numbered with 4-digits (starting from 0000) and outputs a JPEG and PNG image.
Feel free to use, expand, improve or ignore it as you wish.
Cheers,
Pixelfck