Created
January 28, 2018 21:24
-
-
Save leotop/42dba6c06708d6512e7342a96de40ead to your computer and use it in GitHub Desktop.
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
from PIL import Image, ImageEnhance | |
import os | |
from os.path import join | |
def start(): | |
batch("img_source_dir", "img_result_dir", "watermark.png") | |
def batch(infolder, outfolder, watermark): | |
mark = Image.open(watermark) | |
for root, dirs, files in os.walk(infolder): | |
for name in files: | |
im = Image.open(join(root, name)) | |
mark = mark.resize((im.size[0], im.size[1]), Image.ANTIALIAS) | |
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], im.size[1] - mark.size[1]) | |
layer.paste(mark, position) | |
Image.composite(layer, im, layer).save(join(outfolder, name), format="JPEG") | |
start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Водяной знак на картинки в папке