LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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



Reply
 
Search this Thread
Old 09-29-2006, 04:55 AM   #1
saavik
Member
 
Registered: Nov 2001
Location: NRW, Germany
Distribution: SLES11 / FC20/ OES / CentOS
Posts: 606

Rep: Reputation: 32
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 ?
 
Old 09-29-2006, 05:02 AM   #2
scoban
Member
 
Registered: Nov 2004
Location: Turkey
Distribution: Slackware
Posts: 145

Rep: Reputation: 16
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
 
Old 09-29-2006, 05:07 AM   #3
saavik
Member
 
Registered: Nov 2001
Location: NRW, Germany
Distribution: SLES11 / FC20/ OES / CentOS
Posts: 606

Original Poster
Rep: Reputation: 32
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 05:09 AM.
 
Old 09-29-2006, 05:12 AM   #4
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,245
Blog Entries: 16

Rep: Reputation: 233Reputation: 233Reputation: 233
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
 
Old 09-29-2006, 05:26 AM   #5
saavik
Member
 
Registered: Nov 2001
Location: NRW, Germany
Distribution: SLES11 / FC20/ OES / CentOS
Posts: 606

Original Poster
Rep: Reputation: 32
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....
 
Old 09-29-2006, 06:10 AM   #6
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,245
Blog Entries: 16

Rep: Reputation: 233Reputation: 233Reputation: 233
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
 
Old 09-29-2006, 07:32 AM   #7
saavik
Member
 
Registered: Nov 2001
Location: NRW, Germany
Distribution: SLES11 / FC20/ OES / CentOS
Posts: 606

Original Poster
Rep: Reputation: 32
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Opening BMP and JPG images in Solaris 10? as400 Solaris / OpenSolaris 4 05-10-2006 11:19 AM
Convert move frames (avi/dvi/etc) to images(png/jpg/etc) 3saul Linux - Software 1 03-05-2006 10:29 PM
ecw files (very big jpg-like images - satelite photos) under linux MuLaZ Linux - Software 1 04-17-2005 01:27 PM
renaming all JPG to jpg quickk Linux - Newbie 8 09-05-2004 02:23 AM
Small prog to scale down JPG:s kringla Linux - Software 2 08-23-2004 09:27 AM


All times are GMT -5. The time now is 08:43 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration