One more application of the Python Image Library (PIL). This short code creates thumbnails from all JPEG files in the current folder. The thumbnail image file is prefixed with a T_ and saved to the same directory. The program checks for existing files with this prefix, so we don't create T_T_ prefix files and so on.
# experiments with the Python Image Library (PIL) # free from: http://www.pythonware.com/products/pil/index.htm # create 128x128 (max size) thumbnails of all JPEG images in the working folder # Python23 tested vegaseat 25feb2005 # fernandooa modified import glob import Image # get all the jpg files from the current folder for infile in glob.glob("*.jpg"): im = Image.open(infile) # don't save if thumbnail already exists if infile[0:2] != "T_": # convert to thumbnail image im.thumbnail((128, 128), Image.ANTIALIAS) # prefix thumbnail file with T_ im.save("T_" + infile, "JPEG")
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.