[Tutor] adding a watermark to a sequence of images

Michiel Overtoom motoom at xs4all.nl
Mon Jul 21 03:09:45 CEST 2008


Christopher wrote...

> Has anyone used Python to watermark of sequence of images?

No, but I have used PIL (Python Image Library) to do other things to batches
of images, like resizing or printing statistics on it.
Maybe you can get some ideas from these; maybe you can combine them with a
watermarking library.

------------------------------- ShowImageDimensions.py

import os,sys,Image

# See http://www.pythonware.com/library/pil/handbook/introduction.htm

def showdimension(filename):
    im=Image.open(filename)
    print filename,im.size
    
for infile in os.listdir('.'):
    f, e = os.path.splitext(infile)
    if (e=='.tga' or e=='.jpg' or e=='.gif' or e=='.bmp'):
        showdimension(infile)



------------------------------- WoWScreenshotConverter.py

# this converts all TGA's in the current ditectory to JPG's, full-, half-
and small size versions.
# I wrote this in the time when World of Warcraft could not save screenshots
in JPG format.


import os,sys,Image

# See http://www.pythonware.com/library/pil/handbook/introduction.htm
            
def convert(basename):
    print 'Converting',basename
    im=Image.open(basename+'.tga')
    im.save(basename+'-full.jpg')
    # halfsize=tuple(map(lambda x: x/2,im.size))
    halfsize=tuple([x/2 for x in im.size])
    im.thumbnail(halfsize,Image.ANTIALIAS)
    im.save(basename+'-half.jpg')
    thumbsize=128,128
    im.thumbnail(thumbsize,Image.ANTIALIAS)
    im.save(basename+'-small.jpg')
    

# convert('WoWScrnShot_123005_091926.tga')
for infile in os.listdir('.'):
    f, e = os.path.splitext(infile)
    if (e=='.tga'):
        convert(f)

-- 
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Vallopillil
http://www.catb.org/~esr/halloween/halloween4.html



More information about the Tutor mailing list