# Convert all JPG/BMP/GIF files in a folder to PNG format # and create Latex Bounding boxes if MikTex (or more specifically) # xbb.exe is installed # # Modified Giovanni (giovanni@reflections.co.nz) # # Based on a the JPG2PNG.py script found at # http://www.akehrer.com/wiki/code:jpg2png # # Modified to do a bulk conversion of all JPG/BMP/GIF files in a # folder to PNG format. # # Note: No colour profile information is embedded (yet) # # $Id: img2png.py 1156 2007-11-27 09:37:01Z giovanni $ #================================================================= # You may need to install the Python Imaging Library # from # http://www.pythonware.com/products/pil/ #================================================================= # Just run the script - converts all files in the current folder # # if you don't want the xbb files, just delete/comment out the last line ######################################################################## import glob,os,getopt,sys from PIL import Image def getCommandOpts(): infiles = glob.glob("*.jpg"); print infiles; infiles = infiles + glob.glob("*.bmp"); print infiles; infiles = infiles + glob.glob("*.WMF"); print infiles; infiles = infiles + glob.glob("*.gif"); opts, args = getopt.getopt(sys.argv[1:], "i:", ["input",]) for o,a in opts: if o in ("-i","--input"): infiles = glob.glob("%s"%a) return infiles pngNames = ""; # Here's where I collect the PNG file names for xbb for imgfile in getCommandOpts(): print "Converting " + imgfile im = Image.open(imgfile) name = os.path.splitext(imgfile)[0]+".png" im.save(name, "PNG") pngNames += " \"" + name + "\"" # Run XBB to create bounding boxes for all the files at once os.system("xbb -v " + pngNames)