Help with batch watermarking jpg after photobooth

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
photoboothnwb
Posts: 17
Joined: 2018-12-31T12:49:38-07:00
Authentication code: 1152

Re: Help with batch watermarking jpg after photobooth

Post by photoboothnwb »

ok let me compile the images together and upload to show you want I want to achieve.
photoboothnwb
Posts: 17
Joined: 2018-12-31T12:49:38-07:00
Authentication code: 1152

Re: Help with batch watermarking jpg after photobooth

Post by photoboothnwb »

https://i182.photobucket.com/albums/x13 ... keuhql.png (overlay frame 720x480)

https://i182.photobucket.com/albums/x13 ... jpmx45.jpg (source images 720x480)

https://i182.photobucket.com/albums/x13 ... 16k0qw.jpg (resulting image)
convert photobooth00006.jpg watermark.png -gravity northwest -geometry +100+100 -compose over -composite resultimage.jpg

The single command sorta works, but I don't know if it places it on top by default, instead of moving to bottom right.

Sorry that I'm changing the resolutions & file names all over. Basically, it will print to a SELPHY CP1300 printer on 4x6" photo paper.

All images from photobooth will be output to ~/home/pi/Desktop/PHOTOS
Overlay watermark output images will also be in same folder.

Is it possible to replace the original outputted images with the resulting watermarked .jpg so that the printer will automatically print with the watermark overlay?

I can successfully convert it using a single command, but my ultimate goal is to have a script that automatically converts any .jpg images generated in the PHOTOS folder with the watermark overlay before sending it to printer (or if possible add the script to this photobooth program I am using => https://github.com/reuterbal/photobooth)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Help with batch watermarking jpg after photobooth

Post by fmw42 »

The single command sorta works, but I don't know if it places it on top by default, instead of moving to bottom right.
With -gravity northwest, the geometry values will offset from the top left corner. If you want it offset from the bottom right, then use -gravity southeast. -geometry +0+0 will then place it exactly at the bottom right. If you want it moved up or to the left then increase the -geometry settings.

I still do not know where your input images and watermark image reside relative to your command.

I do not have login access to photo bucket to download any of your images from those links.
Is it possible to replace the original outputted images with the resulting watermarked .jpg so that the printer will automatically print with the watermark overlay?
I am confused about this statement. You want to replace the watermark image with the output results or the input images with the output results? If your output directory does not contain any input images, then you may use whatever name you want. But do not use the watermark name since it will be written over by each output image and you will lose the watermark. Please clarify!

Try this format for one image. Fill in your paths to your input, watermark and output directories.

Code: Select all

convert \
\( /path2/backgroundimage \
-set option:filter:filter Lanczos \
-set option:filter:blur 0.8 \
-filter lanczos \
-resize 500x500 \) \
/path2/watermarkimage \
-gravity SouthEast \
-geometry +0+0 \
-composite \
-quality 80 \
/path2/outputfile
adjust -geometry +0+0 (-geometry +X+Y) with X and Y values to offset from the bottom right corner for your watermark. +0+0 will put it right at the bottom right.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Help with batch watermarking jpg after photobooth

Post by fmw42 »

Here is an example that works for me. I have 3 folders on my desktop: in, out and watermark. I cd to the in directory and get the filenames as img. Then in the for loop, I first get the name of the file without the suffix for use in the output. %t is a string format. see https://imagemagick.org/script/escape.php. Then I process each $img in parenthesis to do the resize. Then I provide the path to the watermark directory and image relative to the in directory to get the watermark image. Finally I write the output to the out directory using the innate as part of the output file name with _watermark appended and the .jpg suffix.

Code: Select all

cd
cd desktop/in
for img in *.jpg *.png; do
inname=`convert "$img" -format "%t" info:`
convert \
\( $img \
-set option:filter:filter Lanczos \
-set option:filter:blur 0.8 \
-filter lanczos \
-resize 500x500 \) \
../watermark/cartoon_cat.jpg \
-gravity SouthEast \
-geometry +0+0 \
-composite \
-quality 80 \
../out/"${inname}_watermarked.jpg"
done
Since -gravity southeast and -geometry +0+0 is provided, the watermark image is place in the very bottom right corner.

Note that I put quotes about the $img and ${inname}_watermarked.jpg in case the files in the in directory have spaces in the names.
photoboothnwb
Posts: 17
Joined: 2018-12-31T12:49:38-07:00
Authentication code: 1152

Re: Help with batch watermarking jpg after photobooth

Post by photoboothnwb »

I'm still trying to get it to work sadly :(....

I created 3 folders like you said: in, out, watermark
I created an watermark.sh file w/ script (in the "in" folder, omitting the cd desktop)
Do I change img to the actual file name? or is img just any .jpg in the "in" folder...

#!/bin/bash
for img in *.jpg *.png; do
inname=`convert "$img" -format "%t" info:`convert
( $img
-set option:filter:filter Lanczos
-set option:filter:blur 0.8
-filter lanczos
-resize 500x500 )
../WATERMARK/watermark.png
-gravity SouthEast
-geometry +0+0
-composite
-quality 80
../OUT/"${inname}_watermarked.jpg"
done

when I ran the script, I get:
watermark.sh: line 8: syntax error near unexpected token `$'\r''
'atermark.sh: line 8: `-resize 500x500 )

Not working :/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Help with batch watermarking jpg after photobooth

Post by fmw42 »

First don't make it a script. Just try copying and pasting the commands to a terminal. Second in unix, you must escape the parenthesis with \. See my exact command. Third you did not copy my script code. You are missing a convert before the parenthesis. Be carafull about caps. Is your input directory in or IN. Is your output directory out or OUT? Is your watermark directory watermark or WATERMARK. In multiline command, you must escape the end of line with \. See my exact script. You have some upper case and some lower case. Assuming all are upper case, then try

Code: Select all

cd
cd path2/IN
for img in *.jpg *.png; do
inname=`convert "$img" -format "%t" info:`
convert \
\( $img \
-set option:filter:filter Lanczos \
-set option:filter:blur 0.8 \
-filter lanczos \
-resize 500x500 \) \
../WATERMARK/cartoon_cat.jpg \
-gravity SouthEast \
-geometry +0+0 \
-composite \
-quality 80 \
../OUT/"${inname}_watermarked.jpg"
done
supply your path to your IN directory. If on the desktop, then use cd desktop/IN

But to run the script you will need to preface with bash and run with

bash yourscript.sh
photoboothnwb
Posts: 17
Joined: 2018-12-31T12:49:38-07:00
Authentication code: 1152

Re: Help with batch watermarking jpg after photobooth

Post by photoboothnwb »

Executing it in Terminal works! I have an image w/ watermark in the OUT folder.

pi@raspnode:~ $ cd
pi@raspnode:~ $ cd Desktop/IN
pi@raspnode:~/Desktop/IN $ for img in *jpg *.png; do
> inname=`convert "$img" -format "%t" info:`
> convert \
> \( $img \
> -set option:filter:filter Lanczos \
> -set option:filter:blur 0.8 \
> -filter lanczos \
> -resize 500x500 \) \
> ../WATERMARK/watermark.jpg \
> -gravity SouthEast \
> -geometry +0+0 \
> -composite \
> -quality 80 \
> ../OUT/"${inname}_watermarked.jpg"
> done
convert-im6.q16: unable to open image `*.png': No such file or directory @ error/blob.c/OpenBlob/2701.
convert-im6.q16: no images defined `info:' @ error/convert.c/ConvertImageCommand/3258.
convert-im6.q16: unable to open image `*.png': No such file or directory @ error/blob.c/OpenBlob/2701.
convert-im6.q16: no images defined `../OUT/_watermarked.jpg' @ error/convert.c/ConvertImageCommand/3258.

However, creating a bash script, and executing bash watermark.sh does not work:
#!/bin/bash
cd
cd Desktop/IN
for img in *.jpg *.png; do
inname=`convert "$img" -format "%t" info:`
convert \
\( $img \
-set option:filter:filter Lanczos \
-set option:filter:blur 0.8 \
-filter lanczos \
-resize 600x423 \) \
../WATERMARK/watermark.jpg \
-gravity SouthEast \
-geometry +0+0 \
-composite \
-quality 80 \
../OUT/"${inname}_watermarked.jpg"
done

pi@raspnode:~/Desktop $ bash watermark.sh
watermark.sh: line 3: cd: $'Desktop/IN\r': No such file or directory
watermark.sh: line 4: syntax error near unexpected token `$'do\r''
'atermark.sh: line 4: `for img in *.jpg *.png; do

I placed the shell script in on the Desktop where the folders IN, OUT, WATERMARK are located...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Help with batch watermarking jpg after photobooth

Post by fmw42 »

Are you editing in a Windows tool such as Wordpad or Notepad. Window uses different line endings (\n\r) than Unix systems (\n). It looks like your Unix environment is having trouble with the end of line \r from the windows line endings. Try editing/creating the script in a Unix text editor.
photoboothnwb
Posts: 17
Joined: 2018-12-31T12:49:38-07:00
Authentication code: 1152

Re: Help with batch watermarking jpg after photobooth

Post by photoboothnwb »

Omg it works!!! I opened up the same file using sudo nano watermark.sh, edited the \, crtl-X and saved it, and it ran successfully, converting all imgs in IN to OUT. Thank you!!

My goal is to ultimately and immediately convert any .jpg images sent from Photobooth to IN to be watermarked. Any ideas on how I can have imagemagick running in background and immediately convert any original images to the watermark images in the same folder? The photobooth program uses gphoto2 to generate jpg images capture from a DSLR camera.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Help with batch watermarking jpg after photobooth

Post by fmw42 »

check out cron. It is a unix tool that can be programmed to launch a script at certain time of the day every day. So once you process your files, you can delete them from the OUT directory.
Post Reply