LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-20-2010, 09:01 PM   #1
Raveolution
Member
 
Registered: Mar 2004
Distribution: Fedora & CentOS
Posts: 213
Blog Entries: 2

Rep: Reputation: 26
How about a program to mass-resize jpegs/pngs?


Is there a way to take a whole directory of pictures that are of various dimensions and scale them all down to conform to, say, an 800x600 (or 600x800) boundary?

Better yet is it possible to also ignore and not size-up files that are, say, 400x300?

I am command line savvy so if it can be done via some kind of script I'm cool with that. Thanks!
 
Old 03-20-2010, 09:26 PM   #2
rikijpn
Member
 
Registered: Jun 2007
Location: Japan
Distribution: Debian lenny, DSL, Solaris 10
Posts: 157

Rep: Reputation: 33
gm

how about a script using convert?
http://www.linuxquestions.org/questi...ut-how-655591/
 
Old 03-20-2010, 10:10 PM   #3
raju.mopidevi
Senior Member
 
Registered: Jan 2009
Location: vijayawada, India
Distribution: openSUSE 11.2, Ubuntu 9.0.4
Posts: 1,155
Blog Entries: 12

Rep: Reputation: 92
You can convert them by using GWENVIEW. The resize option does it easy for you !
 
Old 03-20-2010, 10:43 PM   #4
Raveolution
Member
 
Registered: Mar 2004
Distribution: Fedora & CentOS
Posts: 213
Blog Entries: 2

Original Poster
Rep: Reputation: 26
Quote:
Originally Posted by rikijpn View Post
I like gwenview!
But I would like to use convert, too - I don't see a way for convert to intelligently scale the pic like Gwenview does.

Has anyone here used irfanview's batch resizer? I'm trying to replace that.
 
Old 03-21-2010, 01:06 AM   #5
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Quote:
Originally Posted by Raveolution View Post
But I would like to use convert, too - I don't see a way for convert to intelligently scale the pic like Gwenview does.
I think that's the job of an intelligently written script. What exactly do you want to do?

Evo2.
 
1 members found this post helpful.
Old 03-21-2010, 01:47 AM   #6
rikijpn
Member
 
Registered: Jun 2007
Location: Japan
Distribution: Debian lenny, DSL, Solaris 10
Posts: 157

Rep: Reputation: 33
Quote:
Originally Posted by Raveolution View Post
I like gwenview!
But I would like to use convert, too - I don't see a way for convert to intelligently scale the pic like Gwenview does.
I don't understand what you mean by intelligent here. It would help if you'd explain more what you like about gwenview or irfanview's batch resizer, for all of us who don't know them. You can easily check all convert/gm's features by reading its manual.
Again, I don't know gwenview, but if it can do the job (change scale of all pics in a directory, right?) then just use whatever is easier for you.

It does sound more like something a command/script rather than a GUI would do better though. I'd write a script using "convert -resize 800x600" (GraphicsMagick package) to resize the image, and "identify" to check its resolution just in case I wanted to skip some.
All the rest would maybe be a couple of sed or cut sentences.
 
Old 03-21-2010, 03:08 AM   #7
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
Code:
find ./ -maxdepth 1 -exec basename "{}" \; | while read picture; do
  if [ ! "$(identify "$picture" | awk '{print $3}')" = '400x300' ]; then
     xdim=$(identify "$picture" | awk '{print $3}' | awk -Fx '{print $1}')
     ydim=$(identify "$picture" | awk '{print $3}' | awk -Fx '{print $2}')
     [ $xdim -gt $ydim ] && resize='800x' || resize='x800'
     mogrify -scale "$resize" "$picture"
  fi
done
The above resizes a directory full of pictures. It ignores pictures whose size is already 400x300, and the rest of them it resizes so their largest dimension becomes 800, thereby leaving you with a load of pictures that are no larger than 800x??? or ???x800

This uses ImageMagick tools `mogrify` and `identify`, and there are other mogrify options besides "scale" (such as "resize") that you may want to use instead; depends how you want the pictures to turn out.

Your mileage might vary -- Back up your pictures first! Test this on a bunch of spare pictures!!

Sasha

Last edited by GrapefruiTgirl; 03-21-2010 at 03:10 AM.
 
2 members found this post helpful.
Old 03-21-2010, 08:42 PM   #8
Raveolution
Member
 
Registered: Mar 2004
Distribution: Fedora & CentOS
Posts: 213
Blog Entries: 2

Original Poster
Rep: Reputation: 26
Quote:
Originally Posted by GrapefruiTgirl View Post
Code:
etc.
Wicked sick. That works famously. I'm testing it on a few scenarios to see if it works in all cases.
 
Old 03-21-2010, 08:44 PM   #9
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
LOL hopefully 'wicked sick' == 'good' and not 'argh! it formatted my HDD!'

Good luck,

Sasha
 
Old 03-22-2010, 01:03 AM   #10
Raveolution
Member
 
Registered: Mar 2004
Distribution: Fedora & CentOS
Posts: 213
Blog Entries: 2

Original Poster
Rep: Reputation: 26
Quote:
Originally Posted by GrapefruiTgirl View Post
LOL hopefully 'wicked sick' == 'good' and not 'argh! it formatted my HDD!'

Good luck,

Sasha
Nope. Probably because of Murphy's Law - I tested it on a few pics on a memory stick.

Wicked Sick == it worked!
 
Old 03-22-2010, 01:45 AM   #11
Raveolution
Member
 
Registered: Mar 2004
Distribution: Fedora & CentOS
Posts: 213
Blog Entries: 2

Original Poster
Rep: Reputation: 26
Okay here's a bonus question... how to modify that command to do the same thing across several subdirectories (assuming I ever need that function)?
 
Old 03-22-2010, 02:29 AM   #12
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Just omit the "-maxdepth 1" option or change the "1" to however deep you want to go in the directory structure.

Evo2.
 
Old 03-22-2010, 02:43 AM   #13
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
Actually, since I used `basename` you'll have to remove that as well. Remove all of:

Code:
-maxdepth 1 -exec basename "{}" \;
and try that. Note that this code as it is, assumes that all files in these subdirs are pictures (there's not really error handling to speak of), AND that the directories you want to search are all subdirs of the dir you are working in. If there are directories all over the machine, i.e. located in other paths besides the one in which you are running the script, you'll want to add some more code to search specific paths.
 
1 members found this post helpful.
Old 03-22-2010, 06:38 AM   #14
Raveolution
Member
 
Registered: Mar 2004
Distribution: Fedora & CentOS
Posts: 213
Blog Entries: 2

Original Poster
Rep: Reputation: 26
Quote:
Originally Posted by GrapefruiTgirl View Post
Actually, since I used `basename` you'll have to remove that as well. Remove all of:

Code:
-maxdepth 1 -exec basename "{}" \;
and try that. Note that this code as it is, assumes that all files in these subdirs are pictures (there's not really error handling to speak of), AND that the directories you want to search are all subdirs of the dir you are working in. If there are directories all over the machine, i.e. located in other paths besides the one in which you are running the script, you'll want to add some more code to search specific paths.
Jeez. I dig the voodoo that you do so well!
Seriously though, where'd you learn to do this? I've done a mean script or two myself and this is pretty advanced stuff.
 
Old 03-22-2010, 06:12 PM   #15
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
Ahh, no voodoo involved, and honestly, this really isn't very high-tech, but I'm happy that it works for you.

Where to learn this stuff? Just practice and fiddle around. I enjoy scripting -- and lots of other folks do too (though you will also have lots of people tell you to not bother, and to learn another language, depending on what exactly you're trying to do), and there are definitely others around here who are far more advanced scripters than I am. Basically, when you want or need something done, and you don't know C or python or Perl or <blah> or <whatever> other language, and you're determined to do it with a shell script, then just try and try again. I never set out on a mission to "learn scripting inside and out" -- so I don't know the half of it -- but I know how to do what I've needed to learn how to do.

Eventually you end up knowing lots of neat little things, by playing around..

Cheers,

Sasha

Last edited by GrapefruiTgirl; 03-22-2010 at 06:20 PM.
 
  


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
one for ffmpeg experts: it distorts PNGs stabu Linux - Software 2 05-15-2009 09:30 AM
A software to Mass-resize (lots of) pictures? Peacepunk Linux - Software 5 02-04-2009 08:29 AM
what is the best program to resize a movie file ? marozsas Linux - Software 2 01-04-2006 05:51 AM
a need simple a program to resize images while keeping the aspect ratio Necronomicom Linux - Software 3 07-10-2004 12:21 AM
What can I use to resize jpegs via script/command line? davee Linux - Newbie 2 11-03-2003 02:23 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:19 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration