# HG changeset patch # User Simon Cross # Date 1251659131 0 # Node ID c8436f1752d737a194cee07f945bc145aeba7100 # Parent f5f74f1f3a0bdb3e1f663261eb38ae1d59c614a4 Add special handling for different sized sprites. diff -r f5f74f1f3a0b -r c8436f1752d7 regenerate-pngs.py --- a/regenerate-pngs.py Sun Aug 30 18:59:12 2009 +0000 +++ b/regenerate-pngs.py Sun Aug 30 19:05:31 2009 +0000 @@ -6,6 +6,7 @@ def svg_to_png(svg_name, png_name, w, h): """Convert an SVG file to a PNG file.""" + print "Generating %s at %dx%d..." % (png_name, w, h) r = rsvg.Handle(svg_name) scale = max(float(r.props.width) / w, float(r.props.height) / h) @@ -20,15 +21,29 @@ r.render_cairo(ctx) cs.write_to_png(png_name) -def main(path, width, height): +def process_svg_folder(path, width, height): for dirpath, dirnames, filenames in os.walk(path): for filename in filenames: basename, ext = os.path.splitext(filename) if ext == ".svg": svg_name = os.path.join(dirpath, basename + ".svg") png_name = os.path.join(dirpath, basename + ".png") - print "Generating %s at %dx%d..." % (png_name, width, height) svg_to_png(svg_name, png_name, width, height) +def process_sprite(name, width, height, sprite_path): + svg_name = os.path.join(sprite_path, name) + ".svg" + png_name = os.path.join(sprite_path, name) + ".png" + svg_to_png(svg_name, png_name, width, height) + if __name__ == "__main__": - main("data", 20, 20) + tile_path = "data/tiles" + sprite_path = "data/sprites" + sprites = [ + ("chkn", 20, 20), + ("fox", 20, 20), + ("henhouse", 60, 40), + ] + + process_svg_folder("data/tiles", 20, 20) + for name, width, height in sprites: + process_sprite(name, width, height, sprite_path)