Source: Deep Learning on Medium
Creating translucent realistic watermarks with PIL library in Python
Things to accomplish:
1. Find a picture you want to watermark. This will be referred to as background
2. Find a logo or text that will be your watermark, this will be referred to as watermark.
3. The objective is to paste a translucent watermark over the background.
Here is my approach:
Step 1: Import PIL library
Step 2: Create your watermark
if your watermark is text, then you need to create an image with just the text with a transparent background. Here’s how thats done:
1. Create an ‘RGBA’ image with a transparent background. By setting the ‘A’ parameter in RGBA to zero, you get a transparent image
now you have a transparent canvas for watermark.
2. Write the text on this image that is to be the watermark. This is done using the draw function from PIL
The text, in this case, is white (because RGB channels are 255 each). The transparency of the image is 100 (255 is opaque and 0 is transparent)
If the watermark is an image that you have ready, all you’ve to do is convert the image to ‘RGBA’. To do this:
Step 3: Paste the watermark over the background (image to be watermarked)
The final step is to simply paste the watermark on background using paste function.
all functions have an (x,y) coordinate system to place the text/images wherever you want.
‘RGBA’ is denoted by 4 numbers as (r,g,b,a), r=255,g=255,b=255 is white and r=0,g=0,b=0 is black
a = 0 is completely transparent and a = 255 is completely opaque.