5 de set. de 2010

Script Python para cortar todas imagens em um arquivo e salvar

'''
Created on 05/09/2010
@author: tiago buriol
'''
import os
import Image  # PIL - Python Image Library (instale via Sinaptyc)

diretorio = "/home/buriol/PYTHON_PROJECTS/CILAMCE2010/src/ReconstrCROPPED"
arquivos = os.listdir(diretorio)
arquivos.sort()  #ordena os arquivos pelo nome
n=0

# Corta imagens e salva
for arquivo in arquivos:
    fullpath = os.path.join(diretorio,arquivo)
    if os.path.isfile(fullpath):
        n = n + 1
        img = Image.open(fullpath)
        print "Lendo arquivo", n, "de", len(arquivos)
        im =  img.crop([0,0,128,128])
        im.save(os.path.join("/home/buriol/Imagens",arquivo), "BMP")

Nenhum comentário: