Skip to content

Instantly share code, notes, and snippets.

@NalaGinrut
Last active December 19, 2015 05:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NalaGinrut/5902263 to your computer and use it in GitHub Desktop.
Save NalaGinrut/5902263 to your computer and use it in GitHub Desktop.
convert png file to gameduino graphic header. You may need gameduino module of Python
#! /usr/bin/env python
# Be sure you have installed:
# easy_install PIL
# easy_install PySerial
# easy_install gameduino
import Image
import gameduino.prep as gdprep
from sys import argv
def dump_img(pngfile):
(dpic,dchr,dpal) = gdprep.encode(Image.open(pngfile))
imgname = pngfile.rstrip('.png')
hdr = open(imgname+'.h', "w")
gdprep.dump(hdr, imgname+"_pic" ,dpic)
gdprep.dump(hdr, imgname+"_chr" ,dchr)
gdprep.dump(hdr, imgname+"_pal" ,dpal)
hdr.close()
if __name__ == "__main__":
_,pngfile = argv
dump_img(pngfile)
print "%s was generated!\n" % (pngfile.rstrip('.png')+'.h')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment