Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to
LinuxQuestions.org , a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free.
Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please
contact us . If you need to reset your password,
click here .
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
09-29-2006, 03:55 AM
#1
Member
Registered: Nov 2001
Location: NRW, Germany
Distribution: SLES11 / FC14 + 15/ OES / CentOS
Posts: 579
Rep:
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 ?
09-29-2006, 04:02 AM
#2
Member
Registered: Nov 2004
Location: Turkey
Distribution: Slackware
Posts: 142
Rep:
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
09-29-2006, 04:07 AM
#3
Member
Registered: Nov 2001
Location: NRW, Germany
Distribution: SLES11 / FC14 + 15/ OES / CentOS
Posts: 579
Original Poster
Rep:
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!
Last edited by saavik; 09-29-2006 at 04:09 AM .
09-29-2006, 04:12 AM
#4
Senior Member
Registered: Oct 2005
Location: Philippines
Distribution: Gentoo, Slackware, LFS
Posts: 1,526
Rep:
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
09-29-2006, 04:26 AM
#5
Member
Registered: Nov 2001
Location: NRW, Germany
Distribution: SLES11 / FC14 + 15/ OES / CentOS
Posts: 579
Original Poster
Rep:
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....
09-29-2006, 05:10 AM
#6
Senior Member
Registered: Oct 2005
Location: Philippines
Distribution: Gentoo, Slackware, LFS
Posts: 1,526
Rep:
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
09-29-2006, 06:32 AM
#7
Member
Registered: Nov 2001
Location: NRW, Germany
Distribution: SLES11 / FC14 + 15/ OES / CentOS
Posts: 579
Original Poster
Rep:
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
Thread Tools
Search this Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT -5. The time now is 05:10 AM .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know .
Latest Threads
LQ News