I am attaching here the question, my answer and the test output.

I am attaching here the question, my answer and the test output.


Watermark is generally some text or logo overlaid on the photo that identifies who took the photo or who owns the rights to the photo. Pillow package allows us to add watermarks to your images. For adding watermarks to our image, we need “Image”, “ImageDraw” and “ImageFont” modules from the pillow package. The ‘ImageDraw’ module adds functionality to draw 2D graphics onto new or existing images. The ‘ImageFont’ module is employed for loading bitmap, TrueType and OpenType font files. To run the sample code below you will need to download an arial.ttf. Here is a link to a free version I tested wth Arial.ttf Download Example Following python program demonstrates how to add watermark to an image using python pillow − #Import required Image library from PIL import Image, ImageDraw, ImageFont #Create an Image Object from an Image im = Image.open('boy.jpg') width, height = im.size draw = ImageDraw.Draw(im) text = "sample watermark" font = ImageFont.truetype('arial.ttf', 36) textwidth, textheight = draw.textsize(text, font) # calculate the x,y coordinates of the text margin = 10 x = width - textwidth - margin y = height - textheight - margin # draw watermark in the bottom right corner draw.text((x, y), text, font=font) im.show() #Save watermarked image im.save('watermark.jpg') Lab Directions Create a function in Python named my_watermark. The function should take in two parameters: Name of an image file Message - This is text that should be watermarked onto the image Your function should save the watermarked image with the name of the original file with a “_wm” appended to the of the name before the period Your source code should be named watermark.py Test Failed: Failed to import test module: test_simple Traceback (most recent call last): File "/usr/lib/python3.6/unittest/loader.py", line 428, in _find_test_path module = self._get_module_from_name(name) File "/usr/lib/python3.6/unittest/loader.py", line 369, in _get_module_from_name __import__(name) File "/autograder/source/tests/test_simple.py", line 3, in from watermark import my_watermark File "/autograder/source/watermark.py", line 4 from PIL import Image, ImageDraw, ImageFont ^ IndentationError: expected an indented block
Oct 06, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here