Simple script to make .png thumbnails from .zip archive...

K P S ksheka at gmail.com
Tue Jun 20 22:12:54 EDT 2006


Thanks a lot!  This is what I ended up with.
(I would like to get rar archive support, but browsing the web it looks
like rar support isn't in any python library (yet)) :-(  Anyway, I was
able to use the below code unchanged to create thumbnails in nautilus
based on the first .jpg file in a .zip archive.

Is there any rar support module in python?

Thanks again.


#!/usr/bin/python

import zipfile
import sys
import gnomevfs
import Image
import StringIO

inURL=gnomevfs.get_local_path_from_uri(sys.argv[1])
outURL=sys.argv[2]

zip=zipfile.ZipFile(inURL,mode="r")
jpeglist=[x for x in zip.namelist() if '.jp' in x]
try:
  picture=zip.read(jpeglist[0])
except IndexError:
  print 'No jpeg found'

zip.close() #close the file, since we no longer have need of it
image = Image.open(StringIO.StringIO(picture)) # create image object
from file-like object
image.thumbnail((128,128),Image.ANTIALIAS) #create the thumbnail
image.save (outURL, "PNG") #output the file in the proper format




More information about the Python-list mailing list