Skip to content

Commit

Permalink
Now wit is able to move the watermark in 5 different positions.
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasxas committed Oct 11, 2013
1 parent 5a34167 commit fb7237e
Showing 1 changed file with 36 additions and 21 deletions.
57 changes: 36 additions & 21 deletions wit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,41 @@
from os.path import join

def batch():
infolder = os.getcwd()
watermark = str(raw_input('Type the watermark\'s file name (including the .png or .jpg): '))
if not watermark: watermark = "watermark.png"
outfolder = os.getcwd()+"/output/"
if not os.path.exists(outfolder): os.makedirs(outfolder)
mark_dir = infolder+"/"+watermark
mark = Image.open(mark_dir)
for root, dir, files in os.walk(infolder):
if watermark in files: files.remove(watermark)
for name in files:
try:
im = Image.open(join(root, name))
if im.mode != 'RGBA':
im = im.convert('RGBA')
layer = Image.new('RGBA', im.size, (0,0,0,0))
position = (im.size[0]-(mark.size[0]*2), im.size[1]-(mark.size[1]*2))
layer.paste(mark, position)
Image.composite(layer, im, layer).save( join(outfolder, name))
except Exception, (msg):
print ""
infolder = os.getcwd()
p = str(raw_input('Type the watermark\'s position (1 to 5, default: 5): '))
if not p: p = 5
p = int(p)
watermark = str(raw_input('Type the watermark\'s file name (including the .png or .jpg): '))
if not watermark: watermark = "watermark.png"
outfolder = os.getcwd()+"/output/"
mark_dir = infolder+"/"+watermark
mark = Image.open(mark_dir)
for root, dir, files in os.walk(infolder):
if watermark in files: files.remove(watermark)
for name in files:
try:
im = Image.open(join(root, name))
layer = Image.new('RGBA', im.size, (0,0,0,0))
if im.mode != 'RGBA':
im = im.convert('RGBA')
position = getPos(im, mark, p)
layer.paste(mark, position)
if not os.path.exists(outfolder): os.makedirs(outfolder)
Image.composite(layer, im, layer).save( join(outfolder, name))
except Exception, (msg):
print ""

def getPos(ima, mar, pos):
if pos == 1:
return (50, 50)
elif pos == 2:
return (ima.size[0]-(mar.size[0]) -50, 50)
elif pos == 3:
return ((ima.size[0]-mar.size[0])/2 -25, (ima.size[1]-mar.size[1])/2 -25)
elif pos == 4:
return (50, ima.size[1]-(mar.size[1])-50)
else:
return (ima.size[0] - mar.size[0] - 50, ima.size[1]-mar.size[1] - 50)

if __name__ == '__main__':
batch()
batch()

0 comments on commit fb7237e

Please sign in to comment.