Watermarking is a technology of printing less opaque text or symbols on images and items. Believe it or not it’s considered an ancient technology as old as paper since it’s been used on special letters, stamps and printed currency.
As digital imaging has never been such a humongous part of humans’ lives, the usage, creation and demand related to digital images rises as well. Despite the rise of open source and sharing mentality in the digital community, there seems to still be significant room for watermarking applications and so the demand for innovation continues.
Watermarkd is a Python library published by Holypython.com under the open source license Apache-2.0.
In this post we will try to demonstrate what can be accomplished with Watermarkd library.
Watermarkd library allows users to handle watermarking operations in Python directly from the terminal or through use of an optional GUI component.
Since it’s specialized only for watermarking tasks, Watermarkd has a very light graphical user interface. You can probably get an image watermarked (or watermarkd!) during the time it takes to start up a major Image Manipulation software.
It has the most commonly used features when it comes to watermarking and expected to cater to 90% or more of the people looking to watermark an image.
Currently, Watermarkd library consists of one sole class named Spread which houses two functions that spread out watermark text on image(s):
Below you can see various usage types of Watermarkd Library under four titles:
Single function can be used in two main ways:
as simple as passing True argument to gui as below:
single(gui=True)
Let’s first investigate usage scenarios without gui:
import Watermarkd as wmd
wmd.Spread.single(img_path=r"c:/myimage.png")
This code, once executed, will create a watermarkd image on the user’s Desktop. You don’t have to assign gui parameter to False since it’s the default option. So, basically it’s the same thing as this code:
wmd.Spread.single(gui=False, img_path=r"c:/myimage.png")
Also, please note that, when not using gui, the only parameter you have to pass an argument to is img_path, since all the other parameters have default values and hence, they are optional.
Let’s continue to explore other parameters that can be passed to the single function:
Here is another example, in which watermark text is assigned to “Inception”:
from Watermarkd import Spread
f = r"c:/Users/ABC/Desktop/film.png"
Spread.single(img_path=f, wm_text="Inception")
Batch function is very similar to single function with a few subtle differences. First and foremost, it handles a folder of images rather than a single image.
So, img_path parameter is exchanged with folder_path parameter.
Otherwise the rest of the differences are mainly internal which you can check out in the source code if you like.
from Watermarkd import Spread
Spread.batch(folder_path=r"c:/User/ABC/New_Photos")
This code will read all the images from the given folder New_Photos, and create an output folder named Watermarkd_ in user’s Desktop and save all the watermarked files there with the default values for optional parameters. Check out a list of parameters below for adjusting different values such as: watermark text, font size, font type, file name, path name, transparency etc.
If you check out the source code, most of the variable names are also conveniently borrowed from the single function.
Regarding the inner workings of the batch function, the main thing is: it doesn’t apply the watermarking algorithm to a single image, instead watermarking algorithm and positioning etc are placed inside a for loop which iterates through the images in the given folder.
So, in simpler words, folder is iterated with a for loop, image file name is taken which becomes the img_path similar to single function, then watermarking is applied and then files is saved and next iteration starts with the next file.
Here is another example:
from Watermarkd import Spread
f=r"c:/User/ABC/New_Photos"
Spread.batch(folder_path=f, wm_text="Photographer A. C. Jonah, #927-654-92**")
Usage with GUI is pretty straightforward.
Once submit is pressed all the inputs from the user get registered and watermarking process starts.
It can last anywhere between miliseconds to a couple of seconds depending on the resolution of the image. (For the very high resolutions you might need to allow 2-3 seconds which also depends on the availability of computation resources.)
Just as GUI is a new dimension for the Python coder, Packaging also is a new dimension that opens up a whole new world of opportunities and skillset.
To activate GUI component all you have to do is:
Spread.single(gui=True)
You don’t have to pass any other arguments to setting parameters since they’ll be overridden after the GUI is executed.
from Watermarkd import Spread
Spread.single(gui=True)
Usage with GUI in batch function is also simple and straightforward. It’s mostly overlapping with single function’s steps. Here are the main differences:
Once submit is pressed all the inputs from the user get registered and watermarking process will start.
It can last anywhere between miliseconds to a couple of seconds per image depending on the resolution of the image. (For the very high resolutions you might need to allow 2-3 seconds per image which also depends on the availability of computation resources.) After that time watermarked images will be created in the specified folder or default folder if none is specified.
Activate graphical user interface for bath watermarking a folder of images similar to the code in single() function’s case:
from Watermarkd import Spread
Spread.batch(gui=True)
As much as I’d love to see Watermarkd getting used by people with different backgrounds such as:
I’d also love to see it being checked out as a learning tool for Python packaging and Python coding in general. It has all the ingredients necessary to comprehend packaging in Python.
Besides packaging topics such as: Pypi repository publishing, Github hosting, licensing etc. It also has fundamental coding topics, but nothing too complicated to discourage an intermediate or even beginner coder, such as:
Additionally, it’s pretty simple to understand and demonstrates all the ingredients needed to publish a library on PyPI (Python Package Index), such as:
Such topics open up whole new worlds for a programmer to progress towards, you can see them as paths you can take in your journey(Oftentimes you can combine these paths for a great product as well).
If you’re a beginner or intermediate programmer go ahead and create a Github account. Maybe create a trivial repository where you take some notes and save some files if you like, just to start getting familiar with the environment.
If you like Watermarkd or Holypython’s work in general, you’re welcome to visit our Github repos as well. You can read the Watermarkd.py source code along with other necessary files there (setup.py, requirements.txt, __init__.py etc.).
As simple as it is, I hope Watermarkd library serves as a practical solution for people who might need watermarking and I’d love to see it serve educational purposes for coders and developers who never had a chance to explore packaging and publishing topics related to Python.
Thank you so much for visiting.
ps: I’d like to thank creators and contributors of Pillow the Friendly PIL Fork and PySimpleGUI libraries for creating such fantastic libraries and influencing further developments. Also, a huge thank you to Stack Overflow community for sharing so much expert level knowledge and being so kind.
ContentsIntroductionBokeh vs Seaborn & MatplotlibBokeh vs PlotlySummary Introduction As computer science activity booms, you might…
History of Speech-to-Text Models & Current Infrastructure As speech technology continues to advance, so too…
Python Tips & Tricks (Part III) Advanced Level HolyPython.com Here are more Python tips about…
Python Tips & Tricks (Part II) Intermediate Level HolyPython.com The list continues with slightly more…
Almost 15 years after the release of Python 3 many people are wondering when Python…
Introduction We are going to need smart engineering solutions to solve our planet's problems (and…