[Info-vax] simple image processing
Jan-Erik Soderholm
jan-erik.soderholm at telia.com
Thu Aug 18 08:20:31 EDT 2011
Phillip Helbig---undress to reply wrote 2011-08-13 11:20:
> Thus, I'm looking for a quick and easy method to generate
> thumbnails.
OK, here is one working example. Takes 14 sec to convert 124 files
on my 466 Mhz XP900. Two logical names points to the source
and target directories. The logicals are read by Python and the
source dir is scanned. Each file is copied as a thumbnail with
an *_tn.jpg filename to the target dir.
Since Python is a full programming language/environment you can
add any other processing you need.
Notes.
The "for" is a simple way to "walk a directory".
The "splitext" is like f$parse.
All image processing is done by the three im... lines.
Enjoy !
Jan-Erik.
-------------------------------------------------------
$ def source_dir user:[janne.tn_test.source]
$ def target_dir user:[janne.tn_test.target]
$!
$ python
import os, sys
from PIL import Image
from vms.rtl.lib import get_logical
s, src_dir, m_index = get_logical('SOURCE_DIR', 'LNM$FILE_DEV')
s, trg_dir, m_index = get_logical('TARGET_DIR', 'LNM$FILE_DEV')
size = 64, 64
for infile in os.listdir(src_dir):
outfile = trg_dir + os.path.splitext(infile)[0] + \
"_tn" + os.path.splitext(infile)[1]
infile = src_dir + infile
try:
im = Image.open(infile)
im.thumbnail(size)
im.save(outfile, "JPEG")
except IOError:
print "cannot create thumbnail for", infile
-------------------------------------------------------
$ dir <...>4x4*
Directory USER:<JANNE.TN_TEST.SOURCE>
4X4KEYBRD_1.JPG;1 129 29-JUL-2011 16:22:23.59
4X4KEYBRD_2.JPG;1 129 29-JUL-2011 16:22:23.75
4X4KEYBRD_3.JPG;1 323 29-JUL-2011 16:22:23.22
Total of 3 files, 581 blocks.
Directory USER:<JANNE.TN_TEST.TARGET>
4X4KEYBRD_1_TN.JPG;1 3 18-AUG-2011 14:10:28.43
4X4KEYBRD_2_TN.JPG;1 3 18-AUG-2011 14:10:28.54
4X4KEYBRD_3_TN.JPG;1 3 18-AUG-2011 14:10:28.65
Total of 3 files, 9 blocks.
Grand total of 2 directories, 6 files, 590 blocks.
$
More information about the Info-vax
mailing list