how to Watermark all images in sub folders use tile

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?".
liyucmh
Posts: 17
Joined: 2016-01-29T04:53:32-07:00
Authentication code: 1151

how to Watermark all images in sub folders use tile

Post by liyucmh »

dear everyone

I use this to watermark pics in one folders with tile

Code: Select all

#!/bin/bash
for each in /mnt/hgfs/L/tempL/*.jpg
do
s=`du -k $each | awk '{print $1}'`
if [ $s -gt 10 ]; then
   convert -resize 1766 -quality 75 $each $each
   convert /mnt/hgfs/L/tempL/rotate_330_614.png -fill grey50 -colorize 40 miff:- | composite -dissolve 8 -tile -  $each $each 2>/dev/null
    echo "$each: done!"
fi
done
exit 0
now it only process pics in root TempL, how to modify this script to process all pics in folder tempL includes its sub folders

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

Re: how to Watermark all images in sub folders use tile

Post by fmw42 »

As far as I know, Imagemagick does not traverse subdirectories. So you need to script finding each subdirectory and processing each image in the subdirectory.

Proper IM syntax reads the input image before processing such as -resize.

If you use the convert syntax for dissolve rather than composite, you do not need to do a pipe.
liyucmh
Posts: 17
Joined: 2016-01-29T04:53:32-07:00
Authentication code: 1151

Re: how to Watermark all images in sub folders use tile

Post by liyucmh »

fmw42 wrote:As far as I know, Imagemagick does not traverse subdirectories. So you need to script finding each subdirectory and processing each image in the subdirectory.

Proper IM syntax reads the input image before processing such as -resize.

If you use the convert syntax for dissolve rather than composite, you do not need to do a pipe.
can you help me, i am new to imagemagick, i do not how to do a pipe, can you help me write, thanks
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how to Watermark all images in sub folders use tile

Post by fmw42 »

can you help me, i am new to imagemagick, i do not how to do a pipe, can you help me write, thanks
Your code already has a pipe.

Code: Select all

convert /mnt/hgfs/L/tempL/rotate_330_614.png -fill grey50 -colorize 40 miff:- | composite -dissolve 8 -tile -  $each $each 2>/dev/null
The pipe is the | symbol.

Perhaps if you provide an example of your various input images (separately) and output for one image, we can help better.

I am not quite sure what you are asking now.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: how to Watermark all images in sub folders use tile

Post by snibgo »

liyucmh wrote:how to modify this script to process all pics in folder tempL includes its sub folders
That question is about scripting in bash, not about ImageMagick.
snibgo's IM pages: im.snibgo.com
liyucmh
Posts: 17
Joined: 2016-01-29T04:53:32-07:00
Authentication code: 1151

Re: how to Watermark all images in sub folders use tile

Post by liyucmh »

snibgo wrote:
liyucmh wrote:how to modify this script to process all pics in folder tempL includes its sub folders
That question is about scripting in bash, not about ImageMagick.
yes, so how to scripting in bash, i can process all pics, includes sub folders thanks,
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how to Watermark all images in sub folders use tile

Post by fmw42 »

yes, so how to scripting in bash, i can process all pics, includes sub folders thanks,
Your code is already scripting in bash. It starts with

#!/bin/bash

and does its looping in bash. Only the convert and composite commands are Imagemagick.
liyucmh
Posts: 17
Joined: 2016-01-29T04:53:32-07:00
Authentication code: 1151

Re: how to Watermark all images in sub folders use tile

Post by liyucmh »

fmw42 wrote:
can you help me, i am new to imagemagick, i do not how to do a pipe, can you help me write, thanks
Your code already has a pipe.

Code: Select all

convert /mnt/hgfs/L/tempL/rotate_330_614.png -fill grey50 -colorize 40 miff:- | composite -dissolve 8 -tile -  $each $each 2>/dev/null
The pipe is the | symbol.

Perhaps if you provide an example of your various input images (separately) and output for one image, we can help better.

I am not quite sure what you are asking now.
thanks for your reply

now this script can watermark all pics in root folder , but can not process sub folders, how to modified
liyucmh
Posts: 17
Joined: 2016-01-29T04:53:32-07:00
Authentication code: 1151

Re: how to Watermark all images in sub folders use tile

Post by liyucmh »

fmw42 wrote:
yes, so how to scripting in bash, i can process all pics, includes sub folders thanks,
Your code is already scripting in bash. It starts with

#!/bin/bash

and does its looping in bash. Only the convert and composite commands are Imagemagick.
thanks, but it only process root folder TempL, do not process sub folders such as folder1 folder2 in the TempL, how to modify the bash, it can process all pics includes sub folders in TempL?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how to Watermark all images in sub folders use tile

Post by fmw42 »

You will have to find or list all folders you want to process and loop over each one in bash with your script. So you need an outer loop over each folder.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how to Watermark all images in sub folders use tile

Post by fmw42 »

liyucmh
Posts: 17
Joined: 2016-01-29T04:53:32-07:00
Authentication code: 1151

Re: how to Watermark all images in sub folders use tile

Post by liyucmh »

fmw42 wrote:You will have to find or list all folders you want to process and loop over each one in bash with your script. So you need an outer loop over each folder.
so how to write in one script, i am new to bash command, can you help me, thanks
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how to Watermark all images in sub folders use tile

Post by fmw42 »

This is not a bash or unix forum. This is an imagemagick forum. I suggest you request help on a unix bash forum.
vonbiber
Posts: 13
Joined: 2009-08-18T07:55:47-07:00
Authentication code: 8675309

Re: how to Watermark all images in sub folders use tile

Post by vonbiber »

You could use the unix command 'find' to traverse all folders and subfolders.
Provided your pictures are all jpg, something like that will list all the jpg files
found in the top directory /mnt/hgfs/L/tempL and its subfolders:

Code: Select all

#!/bin/bash

find /mnt/hgfs/L/tempL/* -type f -name '*.jpg' | while read each
do
	#display the name found: (replace the line echo "..." by the commands you you want to apply to process the $each file found)
	echo "$each"
done
This assumes that your pictures are all *.jpg. In case some of them are *.JPG or *.Jpg, etc., use '-iname' instead of '-name'
option for

Code: Select all

find
liyucmh
Posts: 17
Joined: 2016-01-29T04:53:32-07:00
Authentication code: 1151

Re: how to Watermark all images in sub folders use tile

Post by liyucmh »

vonbiber wrote:You could use the unix command 'find' to traverse all folders and subfolders.
Provided your pictures are all jpg, something like that will list all the jpg files
found in the top directory /mnt/hgfs/L/tempL and its subfolders:

Code: Select all

#!/bin/bash

find /mnt/hgfs/L/tempL/* -type f -name '*.jpg' | while read each
do
	#display the name found: (replace the line echo "..." by the commands you you want to apply to process the $each file found)
	echo "$each"
done
This assumes that your pictures are all *.jpg. In case some of them are *.JPG or *.Jpg, etc., use '-iname' instead of '-name'
option for

Code: Select all

find
thanks

I have Replaced the for command with

Code: Select all

for each in `find /mnt/hgfs/L/tempL -name '*.jpg'`
now it can work well

but here are new problem, if the sub folder name contain special characters such as Korean word, special characters, it run wrong, how to process folder name that contain special characters ?
Post Reply