You are not logged in.
The following bash script watermarks all images in a folder with a custom caption (in the example "Pittsburgh"):
#!/bin/bash
savedir=".originals"
mkdir $savedir
if [ $? -ne 0 ] ; then
echo "Error: failed making $savedir."
exit 1
fi
for image in *png *jpg *gif
do
if [ -s $image ] ; then # non-zero file size
width=$(identify -format %w $image)
convert -background '#0008' -fill white -gravity center \
-size ${width}x30 caption:Pittsburgh \
$image +swap -gravity south -composite new-$image
mv $image $savedir
mv new-$image $image
echo "watermarked $image successfully"
fi
done
I want a YAD or Zenity box that will pop up and give me the option to enter a customized caption. This will save me having to open up the .sh file and type it in. I would also like the code to be modified so that the original images are kept, and the watermarked images are moved to a subfolder. And I'd also like the ability to only watermark images which I select. The above code watermarks all images in a folder, which is not what I want. I'd like to be able to select, say, 3 images in a folder of 100 images and have only those 3 images watermarked.
Offline
#!/bin/sh
basedir="$(dirname "$(readlink -f "${1}")")"
cd "$basedir"
caption=$(yad --entry --editable --no-buttons --width 410 \
--title="Please enter your Caption and press Enter")
if [ -z "$caption" ]; then
printf "no caption was selected, aborting!\n"
exit 1
fi
printf "caption is $caption"
if [ ! -d "$basedir"/.bakups ]; then
mkdir -p "$basedir"/.bakups
fi
while [ $# -gt 0 ]; do
file=$1
if [ -s $file ]; then
cp -f $file .bakups
convert -background '#0008' -fill white -gravity center \
-size ${width}x30 caption:"$caption" \
$file +swap -gravity south -composite $file && \
printf "\n$file watermarked successfully\n"
fi
shift
done
would also require a custom action
<action>
<icon>system-run</icon>
<name>Add watermak</name>
<unique-id>1424707852190483-2</unique-id>
<command>sh /usr/bin/watermark.sh %F</command>
<description>blah</description>
<patterns>*</patterns>
<image-files/>
</action>
PS: this is just a tiny modification from one of my custom actions(it usally uploads many files to openclipart), so it wont work with folders(you'll have to select multiple image files with CTRL in thunar)
PPS:if you stiil want to list all contents of a folder have a look at the list widget an add checkboxes (yad --help-list), you could use something like "find "<folder>" -maxdepth 1 -type f | grep -E 'png|gif|jpg'" to fill it.
PPPS: (= avoid the use of bash and test you scripts with ksh or dash or you might get a suprise in the future...
*edit: oops, forgot one $image
Last edited by sixsixfive (2015-02-23 17:32:10)
Offline
Thanks, but this isn't working. I tried it on individual images and multiple images. The box comes up and I enter the text and press enter. But nothing happens. You say I have to select multiple images files. So this action would not work on individual files?
What do you mean by "(= avoid the use of bash and test you scripts with ksh or dash or you might get a suprise in the future..."?
Offline
hm stange, i tested this here with with 3 wallpapers try it from the terminal eg: sh <script> "image"
>What do you mean by "(= avoid the use of bash and test you scripts with ksh or dash or you might get a suprise in the future..."?
bash has some features other shells dont' have, so if you change your distribution in the future all your scripts might break(http://mywiki.wooledge.org/Bashism)
Offline
Tx, I tried it again and it worked. Is there a command that will determine the dimensions of the image and automatically adjust the text and dark transparent backdrop to be proportional? As you can see in the below images the watermark is not correctly scaled. The proportions in the first image below are perfect for me. I'd also like the dark transparent layer the text overlays to span the entire width of the bottom of image and the text to be centered, as it does in my original script (as in the below watermarks). I can't get that to work with your script.
Last edited by birch (2015-02-26 21:53:04)
Offline
>Is there a command that will determine the dimensions of the image and automatically adjust the text and dark transparent backdrop to be proportional?
you could use identify and bc to calculate a wanted percentage eg: 10% of the original image
#!/bin/sh
command -v convert >/dev/null 2>&1 || { echo >&2 "I require convert, but it's not installed. aborting!";exit 1;}
command -v identify >/dev/null 2>&1 || { echo >&2 "I require identify, but it's not installed. aborting!";exit 1;}
command -v bc >/dev/null 2>&1 || { echo >&2 "I require bc, but it's not installed. aborting!";exit 1;}
basedir="$(dirname "$(readlink -f "${1}")")"
cd "$basedir"
caption=$(yad --entry --editable --no-buttons --width 410 \
--title="Please enter your caption and press enter:")
if [ -z "$caption" ]; then
printf "no caption was selected, aborting!\n"
exit 1
fi
printf "caption is $caption\n"
if [ ! -d "$basedir"/.bakups ]; then
mkdir -p "$basedir"/.bakups
fi
while [ $# -gt 0 ]; do
file="$1"
if [ -s "$file" ]; then
cp -f "$file" .bakups
imagesize=$(identify -format "%w,%h" "$file")
imagewidth=$(echo "$imagesize" | cut -f1 -d',')
imageheight=$(echo "$(echo "$imagesize" | cut -f2 -d',')*0.1" | bc)
convert -background '#0008' -fill white -gravity center \
-size $(echo $imagewidth)x$(echo $imageheight) caption:"$caption" \
"$file" +swap -gravity south -composite "$file" && \
printf "\n$file watermarked successfully\n"
fi
shift
done
there are alot more im6 examples: http://www.imagemagick.org/Usage/annotating/#annotating
Last edited by sixsixfive (2015-02-26 23:48:05)
Offline
Tx, that works. But it no longer moves the original image into a subfolder. And is there any way to make finer scaling of the watermark height? When I change *0.1" to *0.0" it's too thin, and *0.2" is too high.
Last edited by birch (2015-02-27 23:15:02)
Offline
Tx, that works. But it no longer moves the original image into a subfolder.
oops, forgot to export all variables:
export imagesize=$(identify -format "%w,%h" "$file")
export imagewidth...
export imageheight...
And is there any way to make finer scaling of the watermark height? When I change *0.1" to *0.0" it's too thin, and *0.2" is too high.
0.15?, 1,41421?
Offline
Tx! I found that *0.05000" is the sweet spot.
Last edited by birch (2015-03-01 00:47:14)
Offline
You better have enough of those apple pie pictures to feed everyone .
Regards,
MDM
Offline
birch wrote:Tx, that works. But it no longer moves the original image into a subfolder.
oops, forgot to export all variables:
export imagesize=$(identify -format "%w,%h" "$file") export imagewidth... export imageheight...
birch wrote:And is there any way to make finer scaling of the watermark height? When I change *0.1" to *0.0" it's too thin, and *0.2" is too high.
0.15?, 1,41421?
Where exactly do i place those export variables in the code?
Offline
You better have enough of those apple pie pictures to feed everyone .
Regards,
MDM
sure!:)
Offline
You better have enough of those apple pie pictures to feed everyone .
Regards,
MDM
I don't know, I tried making mine Ala Mode, but the Ice Cream keeps slipping down the screen!
bah weep grana weep ninny bon.
Offline
sixsixfive, I realized that the originals were being copied into a hidden folder .bakup. I removed the periods from the code and now the originals are copied to a non-hidden subfolder called "bakups." This is the final code, for anyone interested:
#!/bin/sh
command -v convert >/dev/null 2>&1 || { echo >&2 "I require convert, but it's not installed. aborting!";exit 1;}
command -v identify >/dev/null 2>&1 || { echo >&2 "I require identify, but it's not installed. aborting!";exit 1;}
command -v bc >/dev/null 2>&1 || { echo >&2 "I require bc, but it's not installed. aborting!";exit 1;}
basedir="$(dirname "$(readlink -f "${1}")")"
cd "$basedir"
caption=$(yad --entry --editable --no-buttons --width 410 \
--title="Please enter your caption and press enter:")
if [ -z "$caption" ]; then
printf "no caption was selected, aborting!\n"
exit 1
fi
printf "caption is $caption\n"
if [ ! -d "$basedir"/bakups ]; then
mkdir -p "$basedir"/bakups
fi
while [ $# -gt 0 ]; do
file="$1"
if [ -s "$file" ]; then
cp -f "$file" bakups
imagesize=$(identify -format "%w,%h" "$file")
imagewidth=$(echo "$imagesize" | cut -f1 -d',')
imageheight=$(echo "$(echo "$imagesize" | cut -f2 -d',')*0.03000" | bc)
convert -background '#0008' -fill white -gravity center \
-size $(echo $imagewidth)x$(echo $imageheight) caption:"$caption" \
"$file" +swap -gravity south -composite "$file" && \
printf "\n$file watermarked successfully\n"
export imagesize=$(identify -format "%w,%h" "$file")
export imagewidth...
export imageheight...
fi
shift
done
And here's some more pies (I used the awesome GIMP plugin G'Mic at the command line to quickly make the montage):
Incidentally, for those interested, I just made the G'Mic command into a Thunar Custom Action.
This action scales the images to 100% of their original size and separates each image with a 5 pixel border. G'Mic 1.6.0.4 must be installed for it to work with the montage function: http://linuxg.net/how-to-install-gmic-1 … e-systems/
Command box:
gmic %N -gimp_montage 4,\""V(H(0,1),H(2,V(3,4)))"\",1,1.0,0,5,0,0,0,255,0,0,0,0 -o -0000.jpg
Under Appearance Conditions click "Image files" and keep asterisk in "File Pattern."
Last edited by birch (2015-03-09 17:30:36)
Offline
you should add the export at the right place
#!/bin/sh
command -v convert >/dev/null 2>&1 || { echo >&2 "I require convert, but it's not installed. aborting!";exit 1;}
command -v identify >/dev/null 2>&1 || { echo >&2 "I require identify, but it's not installed. aborting!";exit 1;}
command -v bc >/dev/null 2>&1 || { echo >&2 "I require bc, but it's not installed. aborting!";exit 1;}
basedir="$(dirname "$(readlink -f "${1}")")"
cd "$basedir"
caption=$(yad --entry --editable --no-buttons --width 410 \
--title="Please enter your caption and press enter:")
if [ -z "$caption" ]; then
printf "no caption was selected, aborting!\n"
exit 1
fi
printf "caption is $caption\n"
if [ ! -d "$basedir"/bakups ]; then
mkdir -p "$basedir"/bakups
fi
while [ $# -gt 0 ]; do
file="$1"
if [ -s "$file" ]; then
cp -f "$file" bakups
export imagesize=$(identify -format "%w,%h" "$file")
export imagewidth=$(echo "$imagesize" | cut -f1 -d',')
export imageheight=$(echo "$(echo "$imagesize" | cut -f2 -d',')*0.03000" | bc)
convert -background '#0008' -fill white -gravity center \
-size $(echo $imagewidth)x$(echo $imageheight) caption:"$caption" \
"$file" +swap -gravity south -composite "$file" && \
printf "\n$file watermarked successfully\n"
fi
shift
done
And here's some more pies (I used the awesome GIMP plugin G'Mic at the command line to quickly make the montage):
Last edited by sixsixfive (2015-03-03 00:17:11)
Offline
you should add the export at the right place
Tx! That works great.
Offline
Hi, where in the script do I place the font command? The default font is okay, but I'd like to be able to change the font if I want. I've tried every which way I could think of, but no dice.
I want this font: -font TSCu_Comic.ttf
Offline
I'd also like to incorporate a canvas resizing into the script. I'd like there to be a black border at the bottom of the image and the watermark will overlay that and not the image, like so:
And then the watermark will go on top of the black border:. The border should scale, since images will have different dimensions.
I currently make a border with XNViewMP and then run the watermark action. But it would be nice to have it done in the actions.
Last edited by yurbev (2016-07-23 21:54:32)
Offline
[ Generated in 0.017 seconds, 7 queries executed - Memory usage: 630.39 KiB (Peak: 663.23 KiB) ]