I have a task of watermarking the image using python pillow. The function is supposed to take in two parameters: 1. Name of an image file and 2.Message - This is text that should be watermarked onto the image
The function should save the watermarked image with the name of the original file with a “_zz” appended to the of the name before the period.
I used the 'classic" python pillow approach:
def watermark (name, message):
from PIL import Image, ImageDraw, ImageFont
im = Image.open(name)
width, height = im.size
draw = ImageDraw.Draw(im)
text = message
font = ImageFont.truetype('arial.ttf', 36)
textwidth, textheight = draw.textsize(text, font)
margin = 10
x = width - textwidth - margin
y = height - textheight - margin
draw.text((x, y), text, font=font)
im.show()
im.save(name+'_zz') # incorrect of course
I can't figure out how to save the file with '_zz" amended to file name only and not to the extension. I am new to Python, please be patient with me...