Skip to content

Instantly share code, notes, and snippets.

@kjaymiller
Last active July 18, 2019 23:23
Show Gist options
  • Save kjaymiller/d8f75a6b260192200e3b75ee7bc30c3a to your computer and use it in GitHub Desktop.
Save kjaymiller/d8f75a6b260192200e3b75ee7bc30c3a to your computer and use it in GitHub Desktop.
Productivity in Tech More Productive Stamp Script
from PIL import Image, ImageDraw, ImageFont
from sys import argv
def watermark_with_transparency(base_image_path,
output_image_path,
watermark_image_path,
title,
position):
base_image = Image.open(base_image_path)
podcast_rez_image = base_image.resize((4000,4000))
watermark = Image.open(watermark_image_path)
smaller_image = watermark.resize((750,750))
mpw = Image.open('more_productive_watermark.png').copy()
mpw = mpw.resize((3000, int(mpw.height * 4.85)),
box=(0,
0,
mpw.width,
mpw.height)) \
.rotate(25, expand=True)
mpw.putalpha(200) # Sets the Opacity of the stamp
more_productive_watermark = list(mpw.getdata())
width, height = podcast_rez_image.size
for i,pixel in enumerate(more_productive_watermark):
if pixel[:3] == (0,0,0):
more_productive_watermark[i] = (0, 0, 0, 0)
title = title
font = ImageFont.truetype("Open_Sans/OpenSans-Regular.ttf", size=18)
transparent = Image.new('RGBA', (width, height), (0,0,0,0))
transparent.paste(podcast_rez_image, (0,0))
transparent.paste(smaller_image, position, mask=smaller_image)
mpw.putdata(more_productive_watermark),
transparent.paste(mpw, (400,
transparent.height-mpw.height), mask=mpw)
img = ImageDraw.Draw(transparent)
img.text((400, 10), title, (51, 148, 250), font=font)
transparent.save(output_image_path)
if __name__ == '__main__':
img = argv[1]
title = argv[2]
watermark_with_transparency(img, 'watermarked_imaged.png',
'watermark.png', position=(100, 100),
title=title)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment