-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import Image, ImageEnhance, os | ||
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 "" | ||
|
||
if __name__ == '__main__': | ||
batch() |