#!/usr/bin/env php $data) { $srcimg = imagecreatefrompng($file); imagealphablending($srcimg, false); imagesavealpha($srcimg, true); imagecopy($img, $srcimg, 0, $y, 0, 0, $data["width"], $data["height"]); imagedestroy($srcimg); $class = sprintf("img_%s", preg_replace("/[^A-Za-z0-9_]/","",preg_replace("/\.png/","",$file))); $css .= sprintf(".%s { display:block; width:%dpx; height:%dpx; background:transparent url(%s) 0px %dpx no-repeat; }\n", $class, $data["width"], $data["height"], $output_img, -$y); $html .= "\n"; $y += $data["height"] + $imgpad; } // Save image imagepng($img, $output_img, 9); imagedestroy($img); // Save css file_put_contents($output_css, $css); // Save demo html file_put_contents($output_html, "

Tiny public domain PHP sprites generator (source)

The image
\"img\"

Individual sprites:

{$html}

"); print "Done, open {$output_html} to see the end result.\n"; ?>