Image resize-watermark-and-move-with-rename loop

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?".
Locked
steveinlimbo
Posts: 1
Joined: 2020-02-20T09:12:46-07:00
Authentication code: 1152

Image resize-watermark-and-move-with-rename loop

Post by steveinlimbo »

im working in ubuntu -- im using gphoto2 to grab images from a tethered dslr camera to a folder then using imagemagick to process and move them .. well, THAT'S the plan anyway... its all meant to just sit and run on a loop and look for/process images .. plllleeease help :P

- i have individual things working but am struggling to tie them together -

ive so far got 'close' to what i want .. but also far far FAR away.
i run the script (ill have it run on auto at startup eventually) .. it cd's into the appropriate folder and then triggers a second script that un-mounts the connected camera (as that throws gphoto2 off) and then triggers gphoto2 to 'listen' for images to be captured and then dumps them in the folder we 'cd''d into.

what i then need to do is, using image magic.. resize, rename (and ideally add timecode info) -add a watermark image - and then move them to a different folder (which is a shared folder - so that i can see them on my network once they have been sorted.

main issues im having is - if there are no images then the script just stops as i cant work out how to 'loop' it .. (after its triggered the secondary script that is) and that also it either moves all the images before it has time to watermark them .. or , if there are a bunch of images it just seems to fail completely .. i need it to work through the images sequentially incase more come in during the processing and fowl things up ... (i was originally just going to run a cron job and batch process the folder - but the images may not get processed that way.
hope that makes sense.


im really sorry but i couldnt see any 'special way' to embed the code in this post - and yes, im a total noob, hence im desperatly asking a forum for help .. thanks in advance for your time. steve

the first bit of code below is the secondary script which fires off and 'looks' for tethered images coming in
********************************************************
********************************************************
********************************************************

********************************************************
#!/bin/bash


echo "**************************************"
echo "* sourcing from cam tethered *"
echo "* *"
echo "*****************************************"
echo " "

gvfs-mount -s gphoto2
gphoto2 --capture-tethered


cd ~/FILES-ON-STARTUP/

done
exit 0
*************************************************************


********************************************************
********************************************************
********************************************************


the following is the main code with my various attempts at moving files coded out - just fails all over the place -



*************************************************************

#!/bin/bash
WATERMARK="$HOME/Pictures/watermark/watermark.png"

echo "***************************************************"
echo "* ok - this script, (when launched from desktop) *"
echo "* will cd into the pics/temp folder then unmount *"
echo "* the dslr camera- then launch a seperate script *"
echo "* which will monitor for dslr pics and dump them *"
echo "* into the pictures/temp folder - the next step *"
echo "* is to get it to loop/wait for those pics, then *"
echo "* watermark and resize them SEQUENTIALLY, then *"
echo "* dump them into the pictures folder (for now) *"
echo "* eventually we'll put them into the shared drive *"
echo "**************************************************"
echo " "

cd ~/Pictures/temp/


sleep 3
gnome-terminal -x sh $HOME/FILES-ON-STARTUP/START-LOOKING-CAM.sh
sleep 3

for each in ~/Pictures/temp/*{.jpg,.jpeg,.png}
do
echo "Working on "$each" ..."
convert -resize 1000 "$each" "$each" >> /dev/null
composite -gravity northeast -dissolve 50.3 $WATERMARK "$each" "$each" -path ../temp2 *.jpg >> /dev/null
echo "... Done!"
done
sleep 5
#mv ~/Pictures/temp/capt*.jpg "$HOME/Pictures"
#mv *.*/*.jpg $HOME/Pictures
exit 0

********************************************************************

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Image resize-watermark-and-move-with-rename loop

Post by snibgo »

What version of IM? If v7, I suggest you use "magick", not "convert" or "composite".

Your second script, if there are any jpeg or PNGs calls "convert" and "composite", and ignores any errors. I suggest you add error-checking.

Your "convert" command should read the file, then resize, then write the file.

"-path" is not a valid option to "composite". The command will fail, and your script won't catch the error.
snibgo's IM pages: im.snibgo.com

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

Re: Image resize-watermark-and-move-with-rename loop

Post by fmw42 »

This command does not make sense to me:
composite -gravity northeast -dissolve 50.3 $WATERMARK "$each" "$each" -path ../temp2 *.jpg >> /dev/null
composite takes two inputs and makes one output. You have 3 inputs and a wild card output jpg. Composite cannot use wild card outputs.

You can write your two commands as one, though I am not sure what you are trying to do or where you want the output. If you want the output as $each, then

Code: Select all

convert "$each" -resize 1000  $WATERMARK  -gravity northeast -define compose:args=50.3 -compose dissolve -composite "$each" >> /dev/null
(see https://imagemagick.org/Usage/compose/#dissolve)

If you want the output with the same name but put in ../temp2 as a jpg file, then

Code: Select all

convert "$each" -set filename:fn "%t" -resize 1000  $WATERMARK  -gravity northeast -define compose:args=50.3 -compose dissolve -composite "%[filename:fn].jpg"  >> /dev/null
(see https://imagemagick.org/Usage/basics/#set)

Locked