[Info-vax] simple image processing
Jan-Erik Soderholm
jan-erik.soderholm at telia.com
Fri Aug 19 10:36:26 EDT 2011
Rich Jordan wrote 2011-08-18 19:48:
> On Aug 18, 7:20 am, Jan-Erik Soderholm<jan-erik.soderh... at telia.com>
> wrote:
>> 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.
>> $
>
> Neat! Thanks for posting that.
Thanks ! :-)
Just for fun, I found another module pre-installed in the Python kit
called EXIF to read the metadata in JPEG files. Here is a short
example runed on a few of the same files as above.
The "open" is a standard file open in "read, binary" mode.
The EXIF.process_file() takes a file handle and extracts
the meta data.
The rest is just a printout of a few of the "keys".
I got over 100 different keys...
Note that one of the keys extracted is "JPEGThumbnail" that
has a thumbnail in JPEG format as it's "value"... :-)
Enjoy !
Jan-Erik.
$ def source_dir user:[janne.tn_test.source]
$!
$ python
import os
import EXIF
from vms.rtl.lib import get_logical
s, src_dir, m_index = get_logical('SOURCE_DIR', 'LNM$FILE_DEV')
for fn in os.listdir(src_dir):
infile = src_dir + fn
handle = open(infile, 'rb')
tags = EXIF.process_file(handle)
print " "
print "File : %s" % (fn)
print "Date : %s" % (tags['Image DateTime'])
print "Exp time: %s" % (tags['EXIF ExposureTime'])
print "Distance: %s" % (tags['MakerNote SubjectDistance'])
print "Sharpnes: %s" % (tags['MakerNote Sharpness'])
handle.close()
$ @ exif.com
File : 4X4KEYBRD_1.JPG;1
Date : 2011:07:28 16:22:17
Exp time: 1/20
Distance: 43
Sharpnes: Normal
File : PC2004A_2.JPG;2
Date : 2011:07:31 17:40:25
Exp time: 1/30
Distance: 38
Sharpnes: Normal
File : TSSP4400_1.JPG;1
Date : 2011:08:06 16:16:59
Exp time: 1/50
Distance: 16
Sharpnes: Normal
More information about the Info-vax
mailing list