| | |
Create Image Thumbnails (Python)
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 import glob import Image # get all the jpg files from the current folder for infile in glob.glob("*.jpg"): im = Image.open(infile) # convert to thumbnail image im.thumbnail((128, 128), Image.ANTIALIAS) # don't save if thumbnail already exists if infile[0:2] != "T_": # prefix thumbnail file with T_ im.save("T_" + infile, "JPEG")
0
•
•
•
•
The Python Image Library (PIL) is now available for Python24.
Download and instal
PIL-1.1.5.win32-py2.4.exe [533k]
from
http://effbot.org/downloads/#imaging
Download and instal
PIL-1.1.5.win32-py2.4.exe [533k]
from
http://effbot.org/downloads/#imaging
0
•
•
•
•
Hello.
Excuse me, I'm really new to python (currently learning the library), and I found your blog by looking for a way for creating thumbnails.
Thanks a million for your snippet, just a question (as I'm so new I might have missed something), wouldnt your snippet be more efficient if it were like this? (well, only in case the folder contained any thumnails)
Excuse me, I'm really new to python (currently learning the library), and I found your blog by looking for a way for creating thumbnails.
Thanks a million for your snippet, just a question (as I'm so new I might have missed something), wouldnt your snippet be more efficient if it were like this? (well, only in case the folder contained any thumnails)
python Syntax (Toggle Plain Text)
import glob import Image # get all the jpg files from the current folder for infile in glob.glob("*.jpg"): if infile[0:2] == "T_": continue # Skipping a thumbnail im = Image.open(infile) # convert to thumbnail image im.thumbnail((128, 128), Image.ANTIALIAS) im.save("T_" + infile, "JPEG")
Similar Threads
- How to provide thumbnails around an image? (HTML and CSS)
- How can I create dynamic thumbnails of Web Pages (PHP)
- Image marquee thumbnails? (JavaScript / DHTML / AJAX)
- any good tutorials on image thumbnails? (PHP)
| Thread Tools | Search this Thread |
abrupt alarm ansi anti approximation assignment avogadro backend beginner binary bluetooth calculator character cmd code customdialog cx-freeze data decimals dictionaries dictionary directory dynamic error examples exe file float format function gnu graphics gui halp heads homework http ideas import input java launcher leftmouse line linux list lists loop module mouse number numbers output parsing path pointer port prime programming progressbar projects push py2exe pygame pyglet pyqt python random recursion schedule screensaverloopinactive script scrolledtext sqlite statistics string strings sudokusolver sum table terminal text thread threading time tlapse tricks tuple tutorial twoup ubuntu unicode urllib urllib2 variable ventrilo wikipedia write wxpython xlib



