11.04.2015 г.

Python search for picture and resize it

# -*- coding: utf-8 -*-
from PIL import Image, ImageFilter, os

format = ["jpg", "JPEG", "jpeg", "png"]
size = (128, 128)


try:
    for root,dirname,filename in os.walk("d:\\snimki"):
        for file in filename:
            if file.endswith(tuple([x for x in format])):
                im = Image.open(os.path.join(root,file))
                print "Original Picture %s is in format %s and mode is %s " % (file, im.size, im.mode)
                im.thumbnail(size)
                im.save(os.path.join(root,"new"+file))
except:
    print "Somthing wrong has with script"

Няма коментари :

Публикуване на коментар