How to add watermark quickly and in bulk

add watermark quickly and in bulk

This is the method I currently use to add watermarks or watermarks to blog images. I usually have enough photos for articles and with this bash script I add the watermark in 2 or 3 seconds.

A while ago i used GIMP for mass editing. This option, which we saw on the blog still valid, but this seems much faster to me and as I say is what I am using now.

This method is also ideal for photographers who have to pass marked images to clients, since in a few seconds you have them processed

Of course, it is a solution for Linux users, I am using Ubuntu. Now I leave you the script and a step-by-step explanation so that you can not only use it but also understand what it does and start learning BASH. There are only 8 lines.

Use Imagemagick you have to install it for the script to work for you. Open terminal and type

sudo apt install imagemagick

With this we can use the ImageMagick functions, crop, resize, lose weight, change the format, combine images, etc, etc. If you want to know more go to its official website.

How does it work

Premiere GituHub with this script. I have yet to learn how to use it well.

watermark script file structure

The system that I have prepared consists of 1 file, 1 image and 2 folders.

Folder beautiful photos is where I put the images to which I want to add the watermark. Y In the folder output is where they appear already edited.

watermark-ikkarocom.png is the watermark I use

archive

And finally there is the .sh file watermark.sh which is the one that contains the code in BASH

If you are not sure what it is and how to work with .sh, here is where to start How to run a .sh file

Explanation of the code step by step.

An easy way to learn BASH programming is by looking at examples of ready-made scripts and programs. This is the code I use.

#!/bin/bash

cd photos
for pic in *; do
    composite -dissolve 90% -gravity southeast -geometry +40+30 ../watermark-ikkarocom.png $pic ${pic//.jpg}-marked.jpg
done
mv *-marked.jpg ../output
rm *

To facilitate understanding I explain it by lines.

#!/bin/bash

It is the shebang, which is used to indicate the interpreter to use for the code.

cd photos

We enter the folder beautiful photos, where we will have left the photos to which we want to add the watermark. This process could also be automated by sending the images directly to the folder from the mobile. But I leave it for later.

for pic in *; do

Start of the for loop, where we tell it that for all the photos in the folder, you have to execute the instructions that follow

composite -dissolve 90% -gravity southeast -geometry +40+30 ../watermark-ikkarocom.png $pic ${pic//.jpg}-marked.jpg

It's the ImageMagick part. We are saying that to the photos in the folder we add another one on top, in this case "watermark-ikkarocom.png" with transparency at 90% or 10% depending on how you want to look at it. Located in the southeast of the image, that is, bottom right and with margins or separation of 40 and 30 px with respect to the background image.

In addition to the name of the images, add the suffix -marked. To be able to differentiate them from those that we have not edited.

Here we could add more instructions and resize the image, lower the weight or compress it.

You can use the name of the watermark you want by changing the watermark-ikarocom.png

done

determines where the for loop ends

mv *-marked.jpg ../output

The images have remained in the photos folder, so with this line we tell you to take all the images with that suffix -marked.jpg and move them to the output folder. Use the relative path. The ../ is to go up from the directory to where the output is found and then enter inside.

rm *

Finally, as we already have our photos in output, we delete all the .jpg files that are in photos.

Improvements

By doing the article I have noticed several improvements.

  • I always save in .jpg format even though the input image is a .png, this can be a problem if the original image has transparency.

Leave a comment