We use exclusively Linux machines, and one of the joys of this choice is the wide range of programs and utilities for all requirements. We like the speed and simplicity of the XFCE4 desktop, but the suggestions in this blog entry should work under any Linux desktop.
When posting images on the Internet, twitter, Instagram, or a blog post, it is usually necessary at least to make the image files that come straight out of today's high-megapixel cameras a rather more manageable size. I like to add some copyright detail, visible on the image and invisible on the exif metadata, as well as some text, usually just my domain name. Some photography programs, like Digikam, provide scripting capability, but I don't always use Digikam, so something that could be used generically offered a better option. To be honest, I can't recall all the starting points for developing the scripts that now work for me, as I have used them for so long, and I see there are some comments in the script that are dated 2014. This blog post was prompted by a recent Linux Journal article about using Imagemagick on the command line, here:- https://www.linuxjournal.com/content/watermarking-images-command-line I find though, that this is one use case where a graphical selection option is easier than staying at the command line.
An example of the result we are looking at is here:-
This example happens to be from a mobile phone. Other pictures on this blog were all put through the scripts under discussion. The script does not alter the relative size of the image, so the proportions remain constant. The text is generated with shadowing techniques, which makes it easier visible on lighter or darker backgrounds. The font can be specified too.
The basic utility that provides all the capability required is Imagemagick. It is possible merely to push a file through Imagemagick and come out with the right result, as well as automating it, such that it will deal with a folder full of images. But I wanted something that would allow me to select images and then process them.
The zenity utility helps with this, as it is a scripting tool for graphical desktops. I have now switched to yad, which does the same job, and which I believe (I may be wrong) is more generic than zenity's gnome roots.
The only other installed utility required is exiv2, for finding and manipulating exif image data.
Among the issues that need to be manged are the orientation of the image. It's annoying if you have a portrait-oriented image that comes out as landscape, with the text vertically across the image. So the script needs to pick up these use cases. I set up the script to allow a destination folder to be chosen, but these days, I drop them all into a "Publishable_Pics" folder, so an option is in the script to allow that.
The idea of this is to use your file manager or other mechanism, such as selecting files from inside a photographic management tool like Digikam or gthumb, then drag the selected images to a desktop icon (I put mine into my "plank" launcher, and also have a desktop icon). Some screen info results, just saying "Processing...", and the processed files end up in the selected destination folder.
The script creates a new file name for the result, rather than use the original file name. The new name is based on the data and time, using seconds as a way of ensuring unique names. Again, I preface the filename with something meaningful to myself, eg TinSlave-215617-20032017.jpg so you can change this to suit yourself.
The script should be reasonably straight forward to understand. I am posting it here warts-and-all, rather than cleaning it all up, as it is mildly interesting to see how the script has evolved over the years I have used it. The only sanitisation I have done is to place variables specific to me, such as my domain name or other text, and destination folder into brackets, like this <XYZ> and put dummy variables in . Remove the brackets when you edit the script for your own info, so <YOUR_TEXT_HERE> will become, for example YOUR_TEXT_HERE. The script could be a lot more parameter-driven, so knock yourself out developing and improving it.
Please make sure you understand what the script does. While there should be nothing in it that will eat your files, it's best to understand and not wildly implement, and indeed, the script should not work properly without a bit of editing of parameters on your part.
Here is an image of my desktop of the script in action. I have selected a couple of files, and am dragging them onto the script icon in my launcher.
The easy bit first. Here is the drag-n-drop information that provides the menu item, and therefore the desktop icon, and usually lives in /usr/share/applications. I have called the file Pics_drag_n_drop.desktop. but you can call it what you like as long as it has the .desktop extension. Note the "%F" as part if the executable. This will become clear in the script.
Comment=Publishable Pics to Desktop
I have called the main script /usr/local/bin/pics-to-tinslave_drag_n_drop.sh, as Tinslave is the nam eof my domain. Of course the name can be changed, but just be consistent, and alter the desktop file accordingly.
## Add a %F to the command line for drag and drop from the desktop
### Script for adding a watermark and copyright info### to images.
##Images are created in a certain size and with particular quality attributes## to create small usable images for the web.
## Requirements: yad, imagemagick, exiv2## Also some patience. Changed from zenity to yad 26-11-14# FRED=$(yad --width=800 --height=500 --file --multiple --title="Choose files to process (mulitples shift-click)")
### Use Zenity (or yad) to choose destination folder and choose files to process
# DEST=$(yad --width=800 --height=400 --file --directory --title="Choose destination folder")#ALTER THIS OR USE THE ABOVE LINE TO SELECT DESTINATION
for SOURCE in "$@"do
#SOURCE=$(echo "$FRED" | tr "|" "\n")#SOURCE="$1"
(echo "$SOURCE" | while read SOURCE;do##########Variables################# Chnage these as you see fit.TMPFILE=TMP-`date +"%H%M%S-%d%m%Y"`.jpg# Provides a template for the resulting file name"RESULT=<YOUR_TEXT>-`date +"%H%M%S-%d%m%Y"`.jpg## Quality is in percent for jpgQUALITY=50## See later in the script for how these are used## Make sure the files exist on your systemFONT="/usr/share/fonts/truetype/Cantarell-Regular.otf"FONT1="/usr/share/fonts/truetype/morris/KelmscottRomanNF.ttf"FONT2="/usr/share/fonts/truetype/Cantarell-Regular.otf"## Two pieces of info written - control the size of each hereFONTSIZE="20"FONTSIZE2="10"#FONTSIZE="35"#FONTSIZE2="12"
TEXT="<YOUR_TEXT_HERE>"#PICSIZE="800x600"## But the following should ensure the aspect ratio remains the same## PICSIZEL is for landscape and PICSIZEP is portrait## You can see what this does - depending on the exiv2 info, the file size## should be the same no matter what orientationPICSIZEL="x700"PICSIZEP="700x"## Where do you want the info written - these are all imagemagick optionsLOCATION=southeastLOCATION2=northwest## What's the copyright textCOPYRIGHT=`echo "Image Copyright "\© "<YOUR_COPYRIGHT_INFO_HERE>. All rights reserved."""`
############## End of Variables ################ Leave this - it's used by the scriptTEMP=/tmp/pic_`date +"%H%M%S-%d%m%Y"`.jpg
## Find orientation of the original## Look for Orientation tag - the last character gives the orientation
ORI=`exiv2 -pv "$SOURCE" | grep Orient| sed -e 's/\(^.*\)\(.$\)/\2/'`
## Now get eventual size relating to orientation## Orientation of 6 or 8 is portrait. 1 or 4 is landscape## But work it out be exceptionif [ "$ORI" -lt 5 ];then PICSIZE=$PICSIZELelse PICSIZE=$PICSIZEPfi
# Temporarily convert the image to required size## so that the resulting fonts sizing remains constant## ie, do the size change first then write the textconvert "$SOURCE" -geometry $PICSIZE -quality $QUALITY $TEMP
## And write the orientation to the temp file#exiv2 -M "set Exif.Image.Orientation $ORI" $TEMP
## Then process it. This order and separately is required## so that the font remains a consistent size
convert -auto-orient $TEMP -font $FONT1 -pointsize $FONTSIZE -draw \"gravity $LOCATION fill grey20 text 0,0 $TEXT \fill grey50 text 5,5 $TEXT fill grey80 text 10,10 $TEXT" \-font $FONT2 -pointsize $FONTSIZE2 \-draw "gravity $LOCATION2 fill white text 3,10 '$COPYRIGHT' \fill black text 8,15 '$COPYRIGHT' " \-matte -bordercolor none -border 0 \$TMPFILE
## Add pretty frame## Hence the need for a TMPFILE rather than straight to RESULTmontage -frame 5 -background '#336699' -geometry +4+4 $TMPFILE $RESULTrm $TMPFILE
## Add copyright data to the fileexiv2 -M"set Exif.Image.Copyright $COPYRIGHT" $RESULT## and set the orientation#exiv2 -M "set Exif.Image.Orientation $ORI" $RESULT
done) \| yad --auto-close --progress --pulsate \--text="Processing" --title="Transforming images..."# yad --text-info --title "That's it" --text "Job complete"
In use: Install imagemagick, exiv2 and yad. These should be in most Linux distros, but are certainly in Debian/Ubuntu and OpenSUSE. Once you have the script installed, edited and marked as executable, just create the desktop icon with the suggestion above. Now open a file manager, select an image, or as many as you like, and drag them to the desktop icon. The script will fire and generate the results in the location you chose in the script, or give you the option of choosing a location if you enable that option in the script.
Again, I am under no illusions about my poor scripting capability, but I do hope that someone gets some ideas for making their own photographic workflow easier from this.