Results 1 to 4 of 4
Hi everybody,
I'm not sure if it is the right place to write this post, but here we go...
I have a lot of images into the server and I've ...
- 03-31-2008 #1Just Joined!
- Join Date
- Jul 2006
- Posts
- 51
[SOLVED] Shell script, image reducing problem
Hi everybody,
I'm not sure if it is the right place to write this post, but here we go...
I have a lot of images into the server and I've write a script to reduce all these images recursively inside all the subdirectories, here is the code:
It works well except when find command finds a subdirectory or a file name with a space in his name, for example:Code:#!/bin/bash for img in `find /home/aleix/photos/ -iname "*.JPG"` do convert -sample 640x480 $img $img done
/home/aleix/photos/2007/photos april/...
or
/home/aleix/photos/2007/april 009.jpg
In these cases script returns an error telling me that it can't find:
Anybody has any idea to resolve it?Code:convert: unable to open file `/home/aleix/photos/2007/photos': The file or directory doesn't exist. convert: unable to open file `april': The file or directory doesn't exist. convert: unable to open image `009.jpg': The file or directory doesn't exist.
Thanks!
Aleix
- 03-31-2008 #2
Try something like this:
Hope this helps.Code:find /home/aleix/photos/ -iname "*.JPG" | xargs -ix convert -sample 640x480 \"x\" \"x\"
--
Bill
Old age and treachery will overcome youth and skill.
- 03-31-2008 #3Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
This snippet has some problems.#!/bin/bash
for img in `find /home/aleix/photos/ -iname "*.JPG"`
do
convert -sample 640x480 $img $img
done
First, you need to quote filenames unless you are sure that no spaces or special characters are contained within the names:
Another big prlblem is that, if there are too many files, bash will not be able to handle the long list. There are two nice ways to handle that correctly, if you want to use a loop, use while:Code:convert -sample 640x480 "$img" "$img"
Or just use the -exec feature:#!/bin/bash
find /home/aleix/photos/ -iname "*.JPG" | while read img
do
convert -sample 640x480 $img $img
done
Code:find /home/aleix/photos/ -iname "*.JPG" -exec convert -sample 640x480 '{}' '{}' \;
- 03-31-2008 #4Just Joined!
- Join Date
- Jul 2006
- Posts
- 51
wje_lf, i92guboj
Thanks for your replies...
the 2nd and the 3th optionts worked perfectly!
thanks a lot!
see you.
Aleix


