How to Create Watermarks with ImageMagick's Convert Command

August 29, 2023

During my conversation with Emily Parker yesterday, we delved into the surge of chatbots and automation. Emily highlighted a major concern: the rise in plagiarism due to easy access to content generation tools. This accessibility facilitates effortless replication of blog posts and visual elements like images. As a response, safeguarding creative work has become crucial. Consequently, the use of watermarks has become widespread, serving as a vital defense against shortcuts that compromise originality.

In this article, we embark on a journey into the realm of image protection and creativity. We'll explore the dynamic capabilities of ImageMagick's convert command, which empowers creators to craft intricate watermarks reminiscent of those employed by industry giants like Shutterstock and iStock. Through a step-by-step breakdown, we'll unravel the techniques that allow you to safeguard your creations while preserving their aesthetic appeal and artistic integrity.

Demystifying the Process

Join us on a journey through the intricacies of ImageMagick's convert command as we recreate watermarking techniques akin to Shutterstock and iStock:

convert input.jpg \
\( -size 100x -background none -fill "rgba(255,255,255,0.1)" -gravity center \
label:"SmartTech101" -trim -rotate -30 \
-bordercolor none -border 10 \
-write mpr:wm \
-delete -1 \
-clone -1 \
-fill mpr:wm  -draw 'color 0,0 reset' \) \
-compose over -composite \
output.jpg

The output is what you see in the title image above.

Now, I will explain what each flag and its argument does step by step.

Step 1: Creating the Canvas for the Watermark

The canvas is created for our watermark which in our example is "SmartTech101".

\(...\): All the settings (ex- -rotate -30) will only affect the image/image sequence in the image stack in the parentheses.

📔 Note: The backslash \ in Unix is used to escape special shell characters like parentheses. However, in Windows, you need to use ^ for the escaping. At the same time, in Windows, you should not have any escaping at all for the parentheses. So, use ( instead of \( in Windows.

-size 100x: width of the watermark is 100 pixels and height is decided automatically based on the content (our watermark - "SmartTech101") and other operations in the command.

-background none: background of the canvas is none i.e. transparent.

Step 2: fill the canvas with your watermark label

-fill <color>: The fill is used to set the color of the font/shape. Here, the color is rgba(255,255,255,0.1) - r for red, g for green, b for blue, a for alpha. The color 255,255,255 is white. So the watermark's color will be white. For black, use 0,0,0. I will suggest you use a black watermark on a light background and a white watermark on a dark background for better contrast. The alpha's range is 0 to 1 - 0 Means fully transparent and 1 means fully opaque. Play with these values to arrive at your liking. The flag -fill can also be followed by memory registers. I will talk about this in the upcoming heading.

-gravity center: ensures that any content (here the label "SmartTech101") added will be centered on the canvas.

label:"SmartTech101": Sets our watermark to the "SmartTech101". You need to replace the "SmartTech101" with your own watermark.

-trim: any transparent edges are removed, resulting in a clean watermark.

-trim flag in Imagemagick's convert

-trim flag in Imagemagick's convert

Step 3: rotate the watermark

-rotate -30: Infuse life into your watermark with a dash of artistry. Rotate the canvas counterclockwise by 30 degrees. This single act bestows depth and energy upon the watermark, reminiscent of the creative flair exhibited by leading stock platforms like Shutterstock.

Step 4: border around the watermark

Continuing the emulation of professional techniques, accentuate your watermark with a delicate border. Envelop the rotated canvas with a border of 10 pixels – a subtle enhancement that mirrors the sophisticated touch employed by industry leaders.

-border 10: sets the border size 10 pixels.

-bordercolor none: border-color is set to none i.e. transparent.

Step 5: The Magic of Memory

Unlock ImageMagick's potential by harnessing memory registers. Employ -write mpr:wm to store the modified image sequence in memory.

The mpr is one of the special output file formats used by ImageMagick. Other formats are miff:, txt:, etc.

Later, mpr:wm will be used to create multiple watermarks pasted in parallel on your input file input.jpg.

Step 6: cloning the watermark

Before the cloning process begins, you need to perform two actions on your image sequence.

Use -delete -1 to delete the last image in the image sequence. You can also +delete. Both are the same.

Use -clone -1 to clone the last image in the image sequence. Or use, +clone.

-fill mpr:wm -draw 'color 0,0 reset': This is the magic behind the cloning process. This duplicates your watermark as many times as possible in parallel at -30 degrees. Because of this, the colors of all the pixels will be replaced with what is passed to the -fill flag i.e. mpr:wm. Since our watermark "SmartTech101" is in the memory mpr:wm, so SmartTech101 is written multiple times in parallel at -30 deg. To learn more about the flag -draw, look at this ImageMagick article.

Step 8: fusion of watermarked canvas with input image

As the command unfolds, experience the art of composition. Employ -compose over -composite to merge the input image with the watermark created above. Witness a harmonious blend that captures the essence of professional watermarking.

Conclusion

ImageMagick's convert command places the power of professional watermarking at your fingertips. Guided by the techniques perfected by Shutterstock and iStock, we've demystified the intricate process of watermark creation. Whether safeguarding your creative work or adding a touch of elegance, mastering these techniques empowers you to echo the finesse of industry giants. Embark on your watermarking journey, armed with the skills to create watermarks that mirror the quality of the most esteemed visual content platforms.

Imagemagick's convert command along with ffmpeg are two of the most important tools available to convert your images using the command line (and also in bulk). In the future, I will talk more about these so keep following my blog.

That's all about creating the watermarks with ImageMagick's convert command. Thanks for reading this article. If you have any suggestions or questions, ask them in the comment section below. To learn more, read the ImageMagick's official manual, and this, and this.