Watermark all images in sub folders
Watermark all images in sub folders
Hello
i have many sub folders, first part over 200 folders. I would like to watermark them.
I know to watermark one by one with this command:
composite -gravity center castle.gif frame.gif castle_button.gif
from http://www.imagemagick.org/Usage/annotating/#overlay
I would like to use script which will watermark all photos in sub folders of directory. I use Lubuntu.
I found that there is solution
viewtopic.php?f=1&t=22379#p93454
but i don't understand how to use it.
Could someone be so kind and help me with this problem.
Thank you.
i have many sub folders, first part over 200 folders. I would like to watermark them.
I know to watermark one by one with this command:
composite -gravity center castle.gif frame.gif castle_button.gif
from http://www.imagemagick.org/Usage/annotating/#overlay
I would like to use script which will watermark all photos in sub folders of directory. I use Lubuntu.
I found that there is solution
viewtopic.php?f=1&t=22379#p93454
but i don't understand how to use it.
Could someone be so kind and help me with this problem.
Thank you.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Watermark all images in sub folders
Code: Select all
cd
list=`find /Users/fred/phillipt18 -type d`
for directory in $list; do
cd $directory
mogrify -format jpg -matte \
-draw 'gravity south image src-over 0,100 250,250 "/Users/fred/phillipt18_igra_logo_trans_500px_0p5.png"' *.jpg
cd
done
list=`find /Users/fred/phillipt18 -type d` -- finds all the subdirectories in the folder at /Users/fred/phillipt18 and make a list of them
for directory in $list; do -- starts looping over each directory in the list
cd $directory -- changes directories to the given directory in the list
mogrify -format jpg -matte \
-draw 'gravity south image src-over 0,100 250,250 "/Users/fred/phillipt18_igra_logo_trans_500px_0p5.png"' *.jpg -- uses mogrify to overlay the watermark image (/Users/fred/phillipt18_igra_logo_trans_500px_0p5.png) to each image in the listed directory (it assumes the watermark image has some transparency so that is why the -matte is used)
cd -- change directories back to the users home directory
done -- iterate to next directory or end the loop
See
http://www.imagemagick.org/Usage/basics/#mogrify
http://www.imagemagick.org/Usage/basics ... fy_compose
http://www.imagemagick.org/script/magic ... aphics.php (for -draw "image...")
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Watermark all images in sub folders
of special note is non-IM scripting methods...
Mogrify-Not -- Batch Processing Alternatives
http://www.imagemagick.org/Usage/basics/#mogrify_not
And for Windows DOS scripting -- Batch processing a (sub-)directory tree
http://www.imagemagick.org/Usage/windows/#for_recursive
WARNING: make a backup of all originals before you even start!!!!
Even if the script creates the watermarked image in a separate file (or directory)
With this type of thing goes wrong, it generally goes wrong in a big way!
Mogrify-Not -- Batch Processing Alternatives
http://www.imagemagick.org/Usage/basics/#mogrify_not
And for Windows DOS scripting -- Batch processing a (sub-)directory tree
http://www.imagemagick.org/Usage/windows/#for_recursive
WARNING: make a backup of all originals before you even start!!!!
Even if the script creates the watermarked image in a separate file (or directory)
With this type of thing goes wrong, it generally goes wrong in a big way!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Watermark all images in sub folders
Thank you guys for reply.
When i want to process i get this error
mogrify: unable to open image `*.jpg': @ error/blob.c/OpenBlob/2587.
I would be appreciate for any help.
fmw42 wrote:cd -- changes directory to your home folderCode: Select all
cd list=`find /Users/fred/phillipt18 -type d` for directory in $list; do cd $directory mogrify -format jpg -matte \ -draw 'gravity south image src-over 0,100 250,250 "/Users/fred/phillipt18_igra_logo_trans_500px_0p5.png"' *.jpg cd done
list=`find /Users/fred/phillipt18 -type d` -- finds all the subdirectories in the folder at /Users/fred/phillipt18 and make a list of them
for directory in $list; do -- starts looping over each directory in the list
cd $directory -- changes directories to the given directory in the list
mogrify -format jpg -matte \
-draw 'gravity south image src-over 0,100 250,250 "/Users/fred/phillipt18_igra_logo_trans_500px_0p5.png"' *.jpg -- uses mogrify to overlay the watermark image (/Users/fred/phillipt18_igra_logo_trans_500px_0p5.png) to each image in the listed directory (it assumes the watermark image has some transparency so that is why the -matte is used)
cd -- change directories back to the users home directory
done -- iterate to next directory or end the loop
See
http://www.imagemagick.org/Usage/basics/#mogrify
http://www.imagemagick.org/Usage/basics ... fy_compose
http://www.imagemagick.org/script/magic ... aphics.php (for -draw "image...")
When i want to process i get this error
mogrify: unable to open image `*.jpg': @ error/blob.c/OpenBlob/2587.
I would be appreciate for any help.
Re: Watermark all images in sub folders
I will now explain in steps what i did.
1.I open gedit and past script.
2. Edit it
cd
list=`find /home/username/Desktop/folder1/folder2 -type d`
for directory in $list; do
cd $directory
mogrify -format jpg \
-draw 'gravity south image src-over 0,100 250,250 "/home/username/Desktop/folder1/logoname.png"' *.jpg
cd
done
3. Save as script.sh
4. I give it permission chmod 775
5. Then i just type in terminal
/home/ovo/Desktop/script.sh
Please let me know if there is something incorrect.
Thank you.
1.I open gedit and past script.
2. Edit it
cd
list=`find /home/username/Desktop/folder1/folder2 -type d`
for directory in $list; do
cd $directory
mogrify -format jpg \
-draw 'gravity south image src-over 0,100 250,250 "/home/username/Desktop/folder1/logoname.png"' *.jpg
cd
done
3. Save as script.sh
4. I give it permission chmod 775
5. Then i just type in terminal
/home/ovo/Desktop/script.sh
Please let me know if there is something incorrect.
Thank you.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Watermark all images in sub folders
A script file needs to know what shell to use, typically it should be
#!/bin/bash
cd
list=`find /home/username/Desktop/folder1/folder2 -type d`
for directory in $list; do
cd $directory
mogrify -format jpg \
-draw 'gravity south image src-over 0,100 250,250 "/home/username/Desktop/folder1/logoname.png"' *.jpg
cd
done
And then it would be called by
bash scriptname.sh
But you can just paste the following into your terminal
cd
list=`find /home/username/Desktop/folder1/folder2 -type d`
for directory in $list; do
cd $directory
mogrify -format jpg \
-draw 'gravity south image src-over 0,100 250,250 "/home/username/Desktop/folder1/logoname.png"' *.jpg
cd
done
#!/bin/bash
cd
list=`find /home/username/Desktop/folder1/folder2 -type d`
for directory in $list; do
cd $directory
mogrify -format jpg \
-draw 'gravity south image src-over 0,100 250,250 "/home/username/Desktop/folder1/logoname.png"' *.jpg
cd
done
And then it would be called by
bash scriptname.sh
But you can just paste the following into your terminal
cd
list=`find /home/username/Desktop/folder1/folder2 -type d`
for directory in $list; do
cd $directory
mogrify -format jpg \
-draw 'gravity south image src-over 0,100 250,250 "/home/username/Desktop/folder1/logoname.png"' *.jpg
cd
done
Is username actually your directory? or Do you really have a specific name in this path for username?/home/username/Desktop/folder1/folder2
Re: Watermark all images in sub folders
fmw42 wrote:A script file needs to know what shell to use, typically it should be
#!/bin/bash
cd
list=`find /home/username/Desktop/folder1/folder2 -type d`
for directory in $list; do
cd $directory
mogrify -format jpg \
-draw 'gravity south image src-over 0,100 250,250 "/home/username/Desktop/folder1/logoname.png"' *.jpg
cd
done
And then it would be called by
bash scriptname.sh
But you can just paste the following into your terminal
cd
list=`find /home/username/Desktop/folder1/folder2 -type d`
for directory in $list; do
cd $directory
mogrify -format jpg \
-draw 'gravity south image src-over 0,100 250,250 "/home/username/Desktop/folder1/logoname.png"' *.jpg
cd
done
Is username actually your directory? or Do you really have a specific name in this path for username?/home/username/Desktop/folder1/folder2
Still not working. I tried direct paste in terminal and also i tried run trough script and i get same error.
I am not sure if is possible with this script but when i instead mogrify put convert
cd
list=`find /home/username/Desktop/folder1/folder2 -type d`
for directory in $list; do
cd $directory
convert -format jpg \
-draw 'gravity south image src-over 0,100 250,250 "/home/username/Desktop/folder1/logoname.png"' *.jpg
cd
done
i get this error
convert: missing an image filename `*.jpg' @ error/convert.c/ConvertImageCommand/3011.
My directory username is different, i just write as example.
Re: Watermark all images in sub folders
f you want to use "convert" rather than "mogrify", then instead of
use
Code: Select all
convert ... *.jpg
Code: Select all
for file in *.jpg
do
convert ... $file
done
Re: Watermark all images in sub folders
Thank you for reply but i am not sure if i putted this part correct.glennrp wrote:f you want to use "convert" rather than "mogrify", then instead ofuseCode: Select all
convert ... *.jpg
Code: Select all
for file in *.jpg do convert ... $file done
Code: Select all
cd
list=`find /home/ovo/Desktop/Nesto/102204004 -type d`
for directory in $list; do
cd $directory
for file in *.jpg
do
convert
-draw 'gravity south image src-over 0,100 250,250 "/home/ovo/Desktop/Nesto/2.png"' *.jpg
done
I prefer mogrify instead of convert, but as i am already in situation that if i don't find solution, i will have to do manual 200+ folders which is only first part, any working solution would make me happy.
Please help if someone have any idea.
Thank you.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Watermark all images in sub folders
you have two loops so you need two finishing "done" statements. Also you must not break an IM command line without a line continuation (\ for unix and ^ for windows). You also need to cd back to the home directory before continuing the directory loop
cd
list=`find /home/ovo/Desktop/Nesto/102204004 -type d`
for directory in $list; do
cd $directory
for file in *.jpg; do
convert -draw 'gravity south image src-over 0,100 250,250 "/home/ovo/Desktop/Nesto/2.png"' *.jpg
done
cd
done
cd
list=`find /home/ovo/Desktop/Nesto/102204004 -type d`
for directory in $list; do
cd $directory
for file in *.jpg; do
convert -draw 'gravity south image src-over 0,100 250,250 "/home/ovo/Desktop/Nesto/2.png"' *.jpg
done
cd
done
Re: Watermark all images in sub folders
Thank you for reply.
I still get error
convert: missing an image filename `*.jpg' @ error/convert.c/ConvertImageCommand/3011.
Do you have ideas or alternative solutions for watermarking all images in sub folderds?
I still get error
convert: missing an image filename `*.jpg' @ error/convert.c/ConvertImageCommand/3011.
Do you have ideas or alternative solutions for watermarking all images in sub folderds?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Watermark all images in sub folders
Sorry I missed something in your command. The input images must come first. You were using mogrify syntax with convert and that will not work. I have fixed that error and improved it to skip directories when looking for files (as long as the file has period in it). The following works fine for me. I am putting the rose mage in the center of a bunch of logo images in several directories:
Note the syntax in the line (and I swapped the order of your single and double quotes)
convert $file -draw "gravity center image src-over 0,0 70,46 '/Users/fred/images/test/rose.png'" ${filename}_new.jpg
Results
Code: Select all
cd
list=`find /Users/fred/images/test -type d`
for directory in $list; do
echo "directory=$directory"
cd $directory
imglist=`ls | grep "\."`
for file in $imglist; do
echo "file=$file"
filename=`convert $file -format "%t" info:`
convert $file -draw "gravity center image src-over 0,0 70,46 '/Users/fred/images/test/rose.png'" ${filename}_new.jpg
done
cd
done
convert $file -draw "gravity center image src-over 0,0 70,46 '/Users/fred/images/test/rose.png'" ${filename}_new.jpg
Results
Code: Select all
directory=/Users/fred/images/test
file=rose.png
file=rose_new.jpg
file=rose_new_new.jpg
file=rose_new_new_new.jpg
directory=/Users/fred/images/test/test1
file=logo.jpg
file=logo1.jpg
file=logo2.jpg
directory=/Users/fred/images/test/test1/test3
file=logo.jpg
file=logo1.jpg
file=logo2.jpg
directory=/Users/fred/images/test/test2
file=logo.jpg
file=logo1.jpg
file=logo2.jpg
Re: Watermark all images in sub folders
Thank you, its working now.
Could you tell me how can i use mogrify instead of convert?
Could you tell me how can i use mogrify instead of convert?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Watermark all images in sub folders
I did that earlier, but you said it did not work for you. The following works for me. But it will replace all the images in your directory tree with ones with the watermark. So it is best if you make a backup of each directory in case of problems.
cd
list=`find /Users/fred/images/test -type d`
echo "list=$list"
for directory in $list; do
echo "directory=$directory"
cd $directory
mogrify -format jpg -draw "gravity center image src-over 0,0 70,46 '/Users/fred/images/test/rose.png'" *.jpg
cd
done
I think you would be better off staying with the convert version.
cd
list=`find /Users/fred/images/test -type d`
echo "list=$list"
for directory in $list; do
echo "directory=$directory"
cd $directory
mogrify -format jpg -draw "gravity center image src-over 0,0 70,46 '/Users/fred/images/test/rose.png'" *.jpg
cd
done
I think you would be better off staying with the convert version.