I'm trying to figure out how to create this kind of watermark, especially the one that's in the center (it's not an ad, it's just a perfect example of what I want to accomplish):
Asked
Active
Viewed 8,242 times
4
-
1You can do this with PIL; the answers to [this question](http://stackoverflow.com/q/5324647/4014959) show how to do it with a normal main image, and also how to do it properly if the main image contains transparency. – PM 2Ring Aug 16 '15 at 10:48
3 Answers
5
Python's wand library has a Image.watermark method that can simplify common watermark operations.
from wand.image import Image
with Image(filename='background.jpg') as background:
with Image(filename='watermark.png') as watermark:
background.watermark(image=watermark, transparency=0.75)
background.save(filename='result.jpg')

emcconville
- 23,800
- 4
- 50
- 66
-
+1 awesome code for watermarking. Is there anyway I could extract original and watermark image from the watermarked pic obtained from above code? – akhi1 Apr 02 '17 at 18:16
3
I don't have python installed where I am, but it should be something like this.
import Image
photo = Image.open("photo.jpg")
watermark = Image.open("watermark.png")
photo.paste(watermark, (0, 0), watermark)
photo.save("photo_with_watermark.jpg")

MyGGaN
- 1,766
- 3
- 30
- 41
2
You can do this with pyvips like this:
#!/usr/bin/python3
import sys
import pyvips
image = pyvips.Image.new_from_file(sys.argv[1], access="sequential")
text = pyvips.Image.text(sys.argv[3], dpi=700, rgba=True)
# scale the alpha down to make the text semi-transparent
text = (text * [1, 1, 1, 0.3]).cast("uchar")
# composite in the centre
image = image.composite(text, "over",
x=int((image.width - text.width) / 2),
y=int((image.height - text.height) / 2))
image.write_to_file(sys.argv[2])
Then run (for example):
$ ./watermark.py PNG_transparency_demonstration.png x.png "Hello world!"
To make:

jcupitt
- 10,213
- 2
- 23
- 39