Hi! Have you ever had the need of placing a logo in multiple images and feared that you could have to do it one by one? Well, fear no more because you don’t! You can do it easily using a program called “convert” which is bundled in the Imagemagick software package. You can even resize both, images and logo, by tweaking the parameters.
After searching for a while on how to do it I wrote a small script to make it easy. Just create a new file, enter the code shown below and save it with the name you want. Just make sure you give it the extension .sh .
#!/bin/bash echo "theBiTbangtheory.com image overlayer!" if [ ! -d ./output ]; then mkdir ./output fi echo "Processing" #overlay images for i in *.jpg; do convert "$i" \( logo1564x192.png -resize 30% \) -gravity SouthEast -geometry +0+5 -composite -format jpg -quality 90 ./output/"$i" echo "$i Done" done
Let’s consider that you saved the file “tbbt_overlay.sh”. Open a console, go to the folder where you saved it and enter the following command:
chmod +x tbbt_overlay.sh
Now you may be wondering how does it work? It processes all the images placed in the folder where you have the script with the .jpeg extension (you can change it to whatever extension you desire in the 10th line of code) and places the result in the “output” folder, which is created by the script if it doesn’t exist.The overlaying operation is in the 11th line of code. The “logo1564x192.png” image is resized to 30% of its size and then applied to the bottom right corner (5 pixels from bottom border) of the image in jpeg format with a quality of 90%. For more information about the operations available and instructions on how to apply them open a console and enter:
To run the script just open a terminal and run it as you run any other script:
I hope you find it useful. You can also download the script here: tbbt_overlay.sh
Did you find this post helpful? Do you wish to contribute to other projects regarding computer science, electronics, robotics or mechatronics that will be posted in this blog? If you wish to do so, you can donate via paypal using the button below. Thanks! 🙂