Hello, I'm still a bit new to all of this, and am extremely happy with PIL.
However, I'm ending up with a slight memory issue.  I'm converting large tif
files (ranging from 400 - 1500 mb in size) to much smaller jpg files, in
large batches.  I open the tif file, resize it, and convert it to jpg.  I
then use the garbagecollector module in python to clear the memory.
However, after running 30-40 of these files through the script, it fails on
me, with a MemoryError.  The script is attached.  I'm curious if you might
have any information, tips, or advice that would assist me in getting it to
work.

-- 
~Shaun
## First we import the image library, Image object, and garbage
## collector, as well as os
from PIL import Image
import gc, os
## Get the path for the directory to be converted, then change to that path
print "Please enter the path to the files that you wish to convert."
path = raw_input()
os.chdir(path)
## For each file in every subdirectory, see if it's a tif file
for root, dir, files in os.walk(path):
    for name in files:
        filename, ext = os.path.splitext(name)
        if ext == ".tif":
            print 'Opening ' + name
            os.chdir(path)
            im = Image.open(root + '/' + name)
            x, y = im.size
            ## Resize the tiff tile at a 2/3 scale.  Make a new directory to
            ## mimic the file heiarchy of the original file, only on the C
            ## drive instead of wherever it was to begin with.
            print 'Resizing'
            im2 = im.resize((int(x*.66), int(y*.66)), Image.ANTIALIAS)
            n = 'c' + root[1:]
            savedfile = n +"/jpegs/"
            try:
                os.makedirs(savedfile)
                os.chdir(savedfile)
            except WindowsError:
                os.chdir(savedfile)
            savedfile = filename + ".jpg"
            ## Save the file as a jpg, with a high quality
            print 'Saving'
            im2.save(savedfile, quality=85)
            del im
            del im2
            ## Force a memory dump.  Otherwise memory will get cluttered
            ## up, very quickly too.
            gc.collect()
            print 'Memory Wiped'
        
_______________________________________________
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig

Reply via email to