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?".
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 »

liyucmh wrote: 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 ?
Have you tried using quotes (")?, e.g.,

Code: Select all

#!/bin/sh

for each in "$(find /mnt/hgfs/L/tempL/* -type f -name '*.jpg')"
do
        echo "$each"
done
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 »

thanks for your help, but still can not work

below is my test code and result

file path:
/mnt/hgfs/L/BaiduYunDownload/tempL/temppic/2016.02.22 [정홍빛은유혹] 분2 68G/test (2).jpg

my code:

Code: Select all

#!/bin/bash
for each in "$(find /mnt/hgfs/L/BaiduYunDownload/tempL/temppic/* -type f -name '*.jpg')"
do
s=`du -k $each | awk '{print $1}'`
if [ $s -gt 10 ]; then
   convert -resize 766 -quality 75 $each $each
   convert /mnt/hgfs/L/BaiduYunDownload/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
it got error message like below
du: cannot access `/mnt/hgfs/L/BaiduYunDownload/tempL/temppic/2016.02.22': No such file or directory
du: cannot access `[정홍빛은]': No such file or directory
du: cannot access `분': No such file or directory
du: cannot access `유혹2': No such file or directory
du: cannot access `68G/test': No such file or directory
du: cannot access `(2).jpg': No such file or directory
./bash.sh: line 5: [: -gt: unary operator expected"

is it the problem of ImageMagick or other, how to do with this problem?
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 »

file path:
/mnt/hgfs/L/BaiduYunDownload/tempL/temppic/2016.02.22 [정홍빛은유혹] 분2 68G/test (2).jpg
Your file path has spaces in it. Thus it must be enclosed in double quotes. I am not sure why vonbiber's solution is not working here. Perhaps it is the parentheses in the file name. Try working with simple filenames and file paths and see if that works on one image.

Perhaps the issue is that your characters are not properly UTF-8 compatible. IM needs UTF-8 compatible characters.
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 »

liyucmh wrote: my code:

Code: Select all

#!/bin/bash
for each in "$(find /mnt/hgfs/L/BaiduYunDownload/tempL/temppic/* -type f -name '*.jpg')"
do
s=`du -k [color=#FF0000]$each[/color] | awk '{print $1}'`
if [ $s -gt 10 ]; then
   convert -resize 766 -quality 75 [color=#FF0000]$each[/color] [color=#FF0000]$each[/color]
   convert /mnt/hgfs/L/BaiduYunDownload/tempL/rotate_330_614.png -fill grey50 -colorize 40 miff:- | composite -dissolve 8 -tile -  [color=#FF0000]$each[/color] [color=#FF0000]$each[/color] 2>/dev/null
    echo "$each: done!"
fi
done
exit 0
Inside your loop, you didn't surround your variable with double-quotes:

Code: Select all

s=$(du -k "$each" | awk '{print $1}')
...
convert ... "$each" ....
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, I would agree. I overlooked the fact that $each needs to be quoted also.

Code: Select all

#!/bin/bash
for each in "$(find /mnt/hgfs/L/BaiduYunDownload/tempL/temppic/* -type f -name '*.jpg')"
do
s=`du -k "$each" | awk '{print $1}'`
if [ $s -gt 10 ]; then
   convert -resize 766 -quality 75 "$each" "$each"
   convert /mnt/hgfs/L/BaiduYunDownload/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
But that only avoids issues with spaces in your filenames. If the characters in the filenames are not proper UTF-8 coded characters, then I do not think IM will read them properly.

If the above does not work, then I would simplify and try one of your oddly nameed images in a simple convert command with quotes and see if that works.

Code: Select all

convert "/mnt/hgfs/L/BaiduYunDownload/tempL/temppic/2016.02.22 [정홍빛은유혹] 분2 68G/test (2).jpg" tmp.jpg
Does this work?
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, I would agree. I overlooked the fact that $each needs to be quoted also.

Code: Select all

#!/bin/bash
for each in "$(find /mnt/hgfs/L/BaiduYunDownload/tempL/temppic/* -type f -name '*.jpg')"
do
s=`du -k "$each" | awk '{print $1}'`
if [ $s -gt 10 ]; then
   convert -resize 766 -quality 75 "$each" "$each"
   convert /mnt/hgfs/L/BaiduYunDownload/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
But that only avoids issues with spaces in your filenames. If the characters in the filenames are not proper UTF-8 coded characters, then I do not think IM will read them properly.

If the above does not work, then I would simplify and try one of your oddly nameed images in a simple convert command with quotes and see if that works.

Code: Select all

convert "/mnt/hgfs/L/BaiduYunDownload/tempL/temppic/2016.02.22 [정홍빛은유혹] 분2 68G/test (2).jpg" tmp.jpg
Does this work?
this work, but only when temppic that contain one picture, that work, when there are two files or more in it , it was wrong

for example, put test.jpg test (2).jpg in folder "2016.02.22 [정홍빛은유혹] 분2 68G", then run, it shows:

du: cannot access `/mnt/hgfs/L/BaiduYunDownload/tempL/temppic/2016.02.22 [정홍빛은유혹] 분2 68G/test (2).jpg\n/mnt/hgfs/L/BaiduYunDownload/tempL/temppic/2016.02.22 [정홍빛은유혹] 분2 68G/test.jpg': No such file or directory
./rewatermark.sh: line 5: [: -gt: unary operator expected
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 »

Run your command

Code: Select all

du
to the file mentioned by Fred:

Code: Select all

du -k "your test file here"
What do you get?
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:Run your command

Code: Select all

du
to the file mentioned by Fred:

Code: Select all

du -k "your test file here"
What do you get?

sorry, i do not know how to chage, can you provide entire code for me to test, my English is poor, thanks
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 »

liyucmh wrote:
vonbiber wrote:Run your command

Code: Select all

du
to the file mentioned by Fred:

Code: Select all

du -k "your test file here"
What do you get?
sorry, i do not know how to chage, can you provide entire code for me to test, my English is poor, thanks
What is the result of this command:

Code: Select all

du -k "/mnt/hgfs/L/BaiduYunDownload/tempL/temppic/2016.02.22 [정홍빛은유혹] 분2 68G/test (2).jpg"
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 »

[root@localhost tempL]# du -k "/mnt/hgfs/L/BaiduYunDownload/tempL/temppic/2016.02.22 [정홍빛은유혹] 분2 68G/test (2).jpg"
0 /mnt/hgfs/L/BaiduYunDownload/tempL/temppic/2016.02.22 [정홍빛은유혹] 분2 68G/test (2).jpg
[root@localhost tempL]#
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 »

liyucmh wrote:[root@localhost tempL]# du -k "/mnt/hgfs/L/BaiduYunDownload/tempL/temppic/2016.02.22 [정홍빛은유혹] 분2 68G/test (2).jpg"
0 /mnt/hgfs/L/BaiduYunDownload/tempL/temppic/2016.02.22 [정홍빛은유혹] 분2 68G/test (2).jpg
[root@localhost tempL]#
According to your script this file wouldn't be processed because

Code: Select all

du -k "/mnt/hgfs/L/BaiduYunDownload/tempL/temppic/2016.02.22 [정홍빛은유혹] 분2 68G/test (2).jpg" | awk '{print $1}'
result would be 0.

But let's go back to your script. Are you sure you put quotes around the 'each' variable? It should read like that:

Code: Select all

#!/bin/bash                                                                        
for each in "$(find /mnt/hgfs/L/BaiduYunDownload/tempL/temppic/* -type f -name '*.jpg')"                                                                              
do                                                                                 
s=$(du -k "$each" | awk '{print $1}')                                              
if [ $s -gt 10 ]; then                                                             
   convert -resize 766 -quality 75 "$each" "$each"                                 
   convert /mnt/hgfs/L/BaiduYunDownload/tempL/rotate_330_614.png -fill grey50 -colorize 40 miff:- | composite -dissolve 8 -tile -  "$each" "$each" 2>/dev/null        
    echo "$each: done!"                                                            
fi                                                                                 
done
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:
liyucmh wrote:[root@localhost tempL]# du -k "/mnt/hgfs/L/BaiduYunDownload/tempL/temppic/2016.02.22 [정홍빛은유혹] 분2 68G/test (2).jpg"
0 /mnt/hgfs/L/BaiduYunDownload/tempL/temppic/2016.02.22 [정홍빛은유혹] 분2 68G/test (2).jpg
[root@localhost tempL]#
According to your script this file wouldn't be processed because

Code: Select all

du -k "/mnt/hgfs/L/BaiduYunDownload/tempL/temppic/2016.02.22 [정홍빛은유혹] 분2 68G/test (2).jpg" | awk '{print $1}'
result would be 0.

But let's go back to your script. Are you sure you put quotes around the 'each' variable? It should read like that:

Code: Select all

#!/bin/bash                                                                        
for each in "$(find /mnt/hgfs/L/BaiduYunDownload/tempL/temppic/* -type f -name '*.jpg')"                                                                              
do                                                                                 
s=$(du -k "$each" | awk '{print $1}')                                              
if [ $s -gt 10 ]; then                                                             
   convert -resize 766 -quality 75 "$each" "$each"                                 
   convert /mnt/hgfs/L/BaiduYunDownload/tempL/rotate_330_614.png -fill grey50 -colorize 40 miff:- | composite -dissolve 8 -tile -  "$each" "$each" 2>/dev/null        
    echo "$each: done!"                                                            
fi                                                                                 
done
yes, it is very strange, I totally use your script above

when two files or more in it, it was wrong
[root@localhost temp]# ./rewatermark.sh
du: cannot access `/mnt/hgfs/L/BaiduYunDownload/tempL/temppic/2016.02.22 [정홍빛은유혹] 분2 68G/test (2).jpg\n/mnt/hgfs/L/BaiduYunDownload/tempL/temppic/2016.02.22 [정홍빛은유혹] 분2 68G/test.jpg': No such file or directory
./rewatermark.sh: line 5: [: -gt: unary operator expected

when i delete test file test.jpg, leave only one file test (2).jp in it, it run well
[root@localhost temp]./rewatermark.sh
/mnt/hgfs/L/BaiduYunDownload/tempL/temppic/2016.02.22 [정홍빛은유혹] 분2 68G/test (2).jpg: done!


really strange
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 »

du: cannot access `/mnt/hgfs/L/BaiduYunDownload/tempL/temppic/2016.02.22 [정홍빛은유혹] 분2 68G/test (2).jpg\n/mnt/hgfs/L/BaiduYunDownload/tempL/temppic/2016.02.22 [정홍빛은유혹] 분2 68G/test.jpg': No such file or directory
It looks to me that the () and space from test (2).jpg are getting lost in the du operation. The find shows /test (2).jpg, but the du is complaining that it cannot access /test.jpg. I really suggest you do not use ( ) and spaces in file and folder names, though double quotes should handle that.
./rewatermark.sh: line 5: [: -gt: unary operator expected
This would appear to indicate that $s is not an integer, because du could not access your file prior to this conditional.

Perhaps you should just test the results of a simpler command and script.

Code: Select all

find /mnt/hgfs/L/BaiduYunDownload/tempL/temppic/* -type f -name '*.jpg'
Does that list all your files? If so, then try

Code: Select all

#!/bin/bash
for each in "$(find /mnt/hgfs/L/BaiduYunDownload/tempL/temppic/* -type f -name '*.jpg')"
do      
echo "$each"
done
If that works, then try

Code: Select all

#!/bin/bash
for each in "$(find /mnt/hgfs/L/BaiduYunDownload/tempL/temppic/* -type f -name '*.jpg')"
do
s=$(du -k "$each" | awk '{print $1}')        
echo "$each $s"
done
That will show what you are getting for $each and for $s, so that you can find out what is getting parsed for your filenames and from du

P.S. Note that the code from vonbiber earlier has quite a lot of extra white space at the ends of each line. I have removed that excess white space in this code here.
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 »

Follow the steps suggested by Fred. Perhaps it would be easier to read the results if you modified the script thus:

Code: Select all

#!/bin/bash

TOP=/mnt/hgfs/L/BaiduYunDownload/tempL/temppic
LOG=/tmp/piclog.txt

cd $TOP || exit 1

rm -f $LOG

for each in "$(find * -type f -name '*.jpg')"
do      
echo "$each" >> $LOG
done
Then read the results in /tmp/piclog.txt
Each line should end with '.jpg'
Post Reply