Page 2 of 2
Re: how to Watermark all images in sub folders use tile
Posted: 2016-07-13T09:59:41-07:00
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
Re: how to Watermark all images in sub folders use tile
Posted: 2016-07-13T20:10:54-07:00
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?
Re: how to Watermark all images in sub folders use tile
Posted: 2016-07-13T20:24:14-07:00
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.
Re: how to Watermark all images in sub folders use tile
Posted: 2016-07-13T23:20:02-07:00
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" ....
Re: how to Watermark all images in sub folders use tile
Posted: 2016-07-13T23:47:09-07:00
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?
Re: how to Watermark all images in sub folders use tile
Posted: 2016-07-14T05:17:46-07:00
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
Re: how to Watermark all images in sub folders use tile
Posted: 2016-07-14T05:38:05-07:00
by vonbiber
Run your command
to the file mentioned by Fred:
What do you get?
Re: how to Watermark all images in sub folders use tile
Posted: 2016-07-14T07:13:04-07:00
by liyucmh
vonbiber wrote:Run your command
to the file mentioned by Fred:
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
Re: how to Watermark all images in sub folders use tile
Posted: 2016-07-14T07:38:55-07:00
by vonbiber
liyucmh wrote:vonbiber wrote:Run your command
to the file mentioned by Fred:
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"
Re: how to Watermark all images in sub folders use tile
Posted: 2016-07-14T18:54:08-07:00
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]#
Re: how to Watermark all images in sub folders use tile
Posted: 2016-07-15T02:20:33-07:00
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
Re: how to Watermark all images in sub folders use tile
Posted: 2016-07-15T06:55:34-07:00
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
Re: how to Watermark all images in sub folders use tile
Posted: 2016-07-15T09:26:26-07:00
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.
Re: how to Watermark all images in sub folders use tile
Posted: 2016-07-15T23:43:51-07:00
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'