Windows context menu command to watermark images
February 13, 2014 in SoftwareImagine someone asked you to provide an effective way to put watermarks on some images before posting them online.
A quick survey online didn’t find any tool that was as effective as:
- select images in the Windows Explorer;
- right-click to bring up the context menu;
- choose “Add watermark”;
- and that’s it, the images are watermarked.
Turns out, such a tool is very easy to connect my go-to image utility - ImageMagick - to the context menu, using built-in Windows tools.
All you need is a batch file and a registry file. You can even do without the batch file if you’re not doing filename modification.
Installing Imagemagick
If you want to make a portable, or easily installed, package out of your script, you should get the portable static build of Imagemagick.
Batch file
"c:\watermark\imagemagick\composite.exe" -gravity southeast c:\watermark\watermark.png "%~1" "%~d1%~p1%~n1_watermarked%~x1"
By file modification I mean appending _watermarked
to the filename. The most native way to do so is to employ percent-tilde directives, a feature of Windows batch files.
Basically %~d1%~p1%~n1
means “entire path to file, but without extension”, and %~x1
means the extension.
In my example, the file is saved at c:\watermark\watermark.bat
, and Imagemagick is installed at c:\watermark\imagemagick
.
Registry file
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\shell\Add watermark]
[HKEY_CLASSES_ROOT\*\shell\Add watermark\command]
@="c:\\watermark\\watermark.bat \"%1\""
If you didn’t need the filename rewriting, you could just specify the command directly in the registry:
@="c:\\watermark\\imagemagick\\composite.exe" -gravity southeast c:\\watermark\\watermark.png \"%1\" \"%1\""
After importing this into the Windows Registry, every file will have an “Add watermark” context menu option, that will run our script. Better yet, you can select as many files as you want and the script will process each of them.
As you can see, with a bit of technical knowledge you can set up convenient tools without relying on third-party programs, which are usually overkill for such a simple task.
By the way, in Mac OS X I would create a service to do the job.
Liked the post? Treat me to a coffee