• A bash script to watermark all the images in a folder (ubuntu, imagemagick, svg)

    by  • 13 gennaio 2012 • tutorial • 0 Comments

    Hello, this time something a bit “nerdy”, i need a script to watermark a batch of images, prior to upload them on Flickr, but all the scripts i’ve found, using ImageMagick, uses a fixed width image and watermark.

    My idea is to automatically resize the watermark to about 50% the width of the image and the apply it.

    This simple script just browse all the files in a folder, with a specific extension (ie *.jpeg, *.JPG, etc) and first read the width of the image, then resize the watermark to the correct size (50%) and then apply it, saving the new image with the same name but in a subfolder.

    Please note, to work this scripts needs that you’ve installed ImageMagick and optionally Zenity and was tested with Ubuntu 11.04.

    Shell
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    #Address of the watermark file
    WATERMARK="url_to_your_watermark_file.svg"
    # Check if the directory "watermarked" exists or create it.
    if [ ! -e "watermarked" ]
    then
    mkdir watermarked
    fi
    #loop inside all the images in folder
    for image in *.jpg *.JPG *.jpeg *.JPEG *.png *.PNG
    do
    if [ ! -e "$image" ] # Check if file exists.
    then
    continue
    fi
    #Retrieve size of the image and divide the lenght by 2
    size=`identify -format %[fx:w/2] $image`
    #Apply the watermark and create a new image in the "watermarked" subfolder
    composite -gravity southeast -background none \( $WATERMARK -geometry ${size} \) ${image} watermarked/${image}
    done
    #If you have installed zenity, a message will popup when the process is complete
    zenity --info --title "Ultramini Watermarker!" --text "Process Complete!"

    If you put this script in your home_folder/.gnome2/nautilus_scripts then you can access it just right-clicking inside the folder with your images and choosing the script in the “scripts” menu

    Lascia un Commento

    L'indirizzo email non verrà pubblicato. I campi obbligatori sono contrassegnati *