views:

32

answers:

3

The title says it all but I want to be able to specify the location in both where to scan and where the converted file will go.

It's just there is a lot of conversions and I've got a script which should sort it for me. Currently I've tried

convert -resize 300x300 >  /media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/normal/*.jpg /media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/tn_med/$1.jpg

and

for i in $( ls /media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/normal); do  /usr/convert resize 360x360 > /media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/normal/$i  /media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/tn_med/$i done;

But no luck any help out there. Thanks Richard

+1  A: 
for i in $( ls /media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/normal); do
    convert -resize 360x360 /media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/normal/$i  /media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/tn_med/$i;
done

got it!

Richard Housham
This won't handle filenames containing spaces.
Kaleb Pederson
A: 

As comments suggested, you can use the find command:

outdir=/media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/tn_med
cd /media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/normal
find . -iname '*.jpg' -print0 | xargs -I{} -0 -r convert -resize 300x300 {} $outdir/{}

By using -print0 and xarg's -0 option, this also handles filenames with spaces and other odd characters.

Kaleb Pederson
A: 

There's no reason to repeat your long directory three times. Use a variable for the base. And don't use ls:

base="/media/usbdisk1/development/ephoto/richard/images/gallery/2007/29"
for file in "$base/normal/*"
do
    convert -resize 360x360 "$file" "$base/tn_med/$(basename $file)"
done

Instead of basename you could do it this way:

    convert -resize 360x360 "$file" "$base/tn_med/${file##*/}"
Dennis Williamson
Thanks to both of you for your help. I hope they work through php exec command - but they should..Thank for the comment about odd chars - there shouldn't be but that's always the case.
Richard Housham