Xfce Forum

Sub domains
 

You are not logged in.

#1 2015-02-23 12:03:43

birch
Member
Registered: 2014-07-12
Posts: 63

Thunar Custom Action - Watermarking Images with YAD

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

#2 2015-02-23 17:02:48

sixsixfive
Member
From: behind you
Registered: 2012-04-08
Posts: 579
Website

Re: Thunar Custom Action - Watermarking Images with YAD

#!/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

#3 2015-02-23 19:06:54

birch
Member
Registered: 2014-07-12
Posts: 63

Re: Thunar Custom Action - Watermarking Images with YAD

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

#4 2015-02-24 09:03:33

sixsixfive
Member
From: behind you
Registered: 2012-04-08
Posts: 579
Website

Re: Thunar Custom Action - Watermarking Images with YAD

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

#5 2015-02-26 21:51:01

birch
Member
Registered: 2014-07-12
Posts: 63

Re: Thunar Custom Action - Watermarking Images with YAD

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.

6SX5k9L.jpg
QgPA8z8.jpg

Last edited by birch (2015-02-26 21:53:04)

Offline

#6 2015-02-26 23:43:55

sixsixfive
Member
From: behind you
Registered: 2012-04-08
Posts: 579
Website

Re: Thunar Custom Action - Watermarking Images with YAD

>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

#7 2015-02-27 23:14:36

birch
Member
Registered: 2014-07-12
Posts: 63

Re: Thunar Custom Action - Watermarking Images with YAD

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

#8 2015-02-28 19:09:06

sixsixfive
Member
From: behind you
Registered: 2012-04-08
Posts: 579
Website

Re: Thunar Custom Action - Watermarking Images with YAD

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?

Offline

#9 2015-03-01 00:42:46

birch
Member
Registered: 2014-07-12
Posts: 63

Re: Thunar Custom Action - Watermarking Images with YAD

Tx! I found that *0.05000" is the sweet spot.

WESVuTm.jpg

u1PbdnL.jpg

Last edited by birch (2015-03-01 00:47:14)

Offline

#10 2015-03-01 04:36:59

MountainDewManiac
Member
From: Where Mr. Bankruptcy is Prez
Registered: 2013-03-24
Posts: 1,115

Re: Thunar Custom Action - Watermarking Images with YAD

You better have enough of those apple pie pictures to feed everyone wink .

Regards,
MDM


Mountain Dew Maniac

How to Ask for Help <=== Click on this link

Offline

#11 2015-03-01 22:02:29

birch
Member
Registered: 2014-07-12
Posts: 63

Re: Thunar Custom Action - Watermarking Images with YAD

sixsixfive wrote:
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

#12 2015-03-01 22:04:23

birch
Member
Registered: 2014-07-12
Posts: 63

Re: Thunar Custom Action - Watermarking Images with YAD

MountainDewManiac wrote:

You better have enough of those apple pie pictures to feed everyone wink .

Regards,
MDM

sure!:)

Offline

#13 2015-03-02 04:00:36

SantaFe
Member
From: Freightyard.
Registered: 2010-09-06
Posts: 97

Re: Thunar Custom Action - Watermarking Images with YAD

MountainDewManiac wrote:

You better have enough of those apple pie pictures to feed everyone wink .

Regards,
MDM

I don't know, I tried making mine Ala Mode, but the Ice Cream keeps slipping down the screen! wink


bah weep grana weep ninny bon. big_smile

Offline

#14 2015-03-02 09:56:21

birch
Member
Registered: 2014-07-12
Posts: 63

Re: Thunar Custom Action - Watermarking Images with YAD

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):

rqARKjg.jpg

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

#15 2015-03-03 00:16:47

sixsixfive
Member
From: behind you
Registered: 2012-04-08
Posts: 579
Website

Re: Thunar Custom Action - Watermarking Images with YAD

you should add the export at the right place wink

#!/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
birch wrote:

And here's some more pies (I used the awesome GIMP plugin G'Mic at the command line to quickly make the montage):

rqARKjg.jpg

ja6EMyU.gif

Last edited by sixsixfive (2015-03-03 00:17:11)

Offline

#16 2015-03-05 10:40:38

birch
Member
Registered: 2014-07-12
Posts: 63

Re: Thunar Custom Action - Watermarking Images with YAD

sixsixfive wrote:

you should add the export at the right place wink

Tx! That works great.

Offline

#17 2016-07-23 21:31:18

yurbev
Member
Registered: 2016-04-18
Posts: 54

Re: Thunar Custom Action - Watermarking Images with YAD

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

#18 2016-07-23 21:45:06

yurbev
Member
Registered: 2016-04-18
Posts: 54

Re: Thunar Custom Action - Watermarking Images with YAD

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:

lZ6YAnR.jpg

And then the watermark will go on top of the black border:. The border should scale, since images will have different dimensions.

qBamFiX.jpg

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

Board footer

Powered by FluxBB