LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   recrusiv scale of jpg images (http://www.linuxquestions.org/questions/programming-9/recrusiv-scale-of-jpg-images-487924/)

saavik 09-29-2006 03:55 AM

recrusiv scale of jpg images
 
Hy!

I plan a jpeg archive for our complany.

Unfortunatelly some people think they have to save there pictures with 5.1 mil. pixels so my database keeps growing.

Now my question:

I can use:

for f in *.jpg ; do djpeg $f | pnmscale -xysize 1024 768 | cjpeg -qual 75 >1024-$f ; done

to resale the jpegs to 1024x768 but as the users are able to create there own subfolders I would like to uses the string above recrusivly.

Who can i do that ?

scoban 09-29-2006 04:02 AM

Go to top directory

find . -type f -name "*.jpg" -print | while read x; do djpeg $x | pnmscale -xysize 1024 768 | cjpeg -qual 75 >1024-$x ; done

saavik 09-29-2006 04:07 AM

Ok, but

-bash: 1024-./public/img_2684_2.jpg: Datei oder Verzeichnis nicht gefunden

seems to me that $x could not be uses as it does not only store the filename but the whole path. trying to figer that out.....

Should be something with awk -F/ {'print$2'}

Thanks!

konsolebox 09-29-2006 04:12 AM

try this command. please test it first.

Code:

OLDIFS=$IFS; IFS=$'\n'
for f in $(find -type f | grep -i "\.jpg$"); do
        d=${f/\/*}; [ -z "$d" ] && d=.
        djpeg $f | pnmscale -xysize 1024 768 | cjpeg -qual 75 > ${d}/1024-$f
done
IFS=$OLDIFS


saavik 09-29-2006 04:26 AM

same mistake

./test.scr: line 4: ./1024-./public/img_2684.jpg: Datei oder Verzeichnis nicht gefunden

the './1024' is at the wrong place.

Two strings have to be used as

1.) I need the whole path as the source
2.) as target i need the folder then i would like to insert 1024 and then comes the old filename....


lets see....

konsolebox 09-29-2006 05:10 AM

sorry my mistake. used dirname instead.

Code:

OLDIFS=$IFS; IFS=$'\n'
for f in $(find -type f | grep -i "\.jpg$"); do
        d=$(dirname $f)
        djpeg $f | pnmscale -xysize 1024 768 | cjpeg -qual 75 > ${d}/1024-$f
done
IFS=$OLDIFS


saavik 09-29-2006 06:32 AM

got it working....


Ok, its not so beautiful but IT WORKS


find . -type f -name "*.jpg" -print | grep -v 1024_768_ | while read x; do
echo ALT:$x
pfad=`dirname $x`
dateiname=`basename $x`
echo NEU:$pfad/1024_768_$dateiname
djpeg $x | pnmscale -xysize 1024 768 | cjpeg -qual 75 >$pfad/1024_768_$dateiname
chown wwwrun $pfad/1024_768_$dateiname
chmod 600 $pfad/1024_768_$dateiname
mv $x /tempbilder/
done


All times are GMT -5. The time now is 03:56 AM.