A Python 3.10 program which autonomizes the application of watermarks to a specified set of images. Apart from automatic watermarking, it also supports auto watermark color inversion and auto watermark scaling.
This software was developed by Nico Ismaili with the primary purpose of facilitating the selling of photographs.
To be able to run the program and install the required dependencies you will need to have Python 3.10 and pipenv installed.
Clone the repository, navigate to the project folder and run pipenv install
to install all required dependencies.
Then run watermarker.py by using the following command:
python watermarker.py
Afterwards, a folder named unmarked should open, in which unmarked images can be placed. Also in this folder is the marked directory, in which marked images will appear.
To change the paths to both folders, as well as the watermark image, please refer to the next chapter.
Access to all configurable parameters of WaterMarker can be obtained by opening the config.json file in any text editor. In the file a variety of values can be fitted to one's specific needs. The name, type, range, default value and explanation of each configurable parameter can be found in the table below.
Name | Type | Range | Default Value | Explanation |
---|---|---|---|---|
unmarkedDirPath | string | - | "./resource/unmarked" | Path to the folder in which unmarked images will be placed. |
markedDirPath | string | - | "./resource/unmarked/marked" | Path to the folder in which marked images will be stored. |
watermarkPath | string | - | "./resource/watermark" | Path to the watermark image PNG file. To get the best results color your watermark either compeletely white or black. |
rel_size | float | 0 to 1 | 0.03 | Defines the scale of the watermark as a percentage of the total area of the base image. |
padding | float or [int, int] | 0 to 1 or [x, y], where x and y are whole numbers. | 0.6 | Either an int list, from which the [0] defines the horizontal and [1] the vertical padding, or a percentage of the watermark pixel height, which will then be used as padding on both axes. |
pos | string | "TL", "TR", "BL" or "BR" | "BL" | Defines the where the watermark will be pasted onto the base image. TL = top-left, TR = top-right, BL = bottom-left and BR = bottom-right. |
opacity | float | 0 to 1 | 0.7 | Defines the opacity of the watermark. |
threshold | int | 0 to 255 | 150 | Defines the threshold value of when the algorithm defines an area as bright or dark. Only change this value if their is an issue with brightness detection. |
rec_watch | boolean | true or false | false | Flag which defines if the unmarked folder should be watched recursively, meaning changes in all subfolders will be acted upon. Set this value to false if your marked folder is inside your unmarked folder. |
Please restart the program for changes to take effect.
WaterMarker runs on all Python compatible operating systems. If you experience an error on your system, please do not hesitate to open a new issue concerning your problem.
As input images the current version of WaterMarker only supports the .jpg image format. Watermark images must be in .png format.
In this section two different images, one bright and one dark, are to be marked. Additionally, cropped versions of each image have been provided to showcase the software's automatic relative sizing capabilities.
These are the images which were put inside the unmarked directory.
This is what was outputted by WaterMarker into the marked directory.
The bright sample photo was created by Alexey Lin.
The dark sample photo was created by Osman Rana.