LinuxQuestions.org
Visit Jeremy's Blog.
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 10-11-2004, 05:59 PM   #1
BaltikaTroika
Member
 
Registered: Sep 2004
Distribution: Debian 4.0, Ubuntu 6.10, Ubuntu Server 6.06
Posts: 134

Rep: Reputation: 15
Resizing images quickly?


Is there any batch image resizing program out there for Linux? I've got a ton of high res photos from my digital camera I want to send via email, but don't really want to go in and do it all by hand for each one.

Thanks for any info,
Baltika
 
Old 10-11-2004, 06:11 PM   #2
Dave Kelly
Member
 
Registered: Aug 2004
Location: Todd Mission Texas
Distribution: Linspire
Posts: 213

Rep: Reputation: 31
Change to the directory where the jpegs reside and run this script.

for i in *jpg; do echo $i; convert -size 320x240 $i -resize 320x240 $i; done

I use it for images in HTML code. Change the 320x240 to whatever you want.
 
Old 10-11-2004, 06:27 PM   #3
stonecrest
Member
 
Registered: Sep 2004
Distribution: Arch :D
Posts: 66

Rep: Reputation: 15
Wow, I was wondering the same thing. Thanks for the tip, Dave!

One question though.. is there a way to specify a height and have the width adjusted based on the aspect ratio of the pictures? I would basically like images of various sizes to end up with a height of 50 pixels and a width of whatever it takes to keep the aspect ratio constant.
 
Old 10-11-2004, 07:55 PM   #4
Dave Kelly
Member
 
Registered: Aug 2004
Location: Todd Mission Texas
Distribution: Linspire
Posts: 213

Rep: Reputation: 31
I don't have an answer to your question because I have never ask myself that question. I remember that HTML code will allow you to use only one dimension and auto-size the other.

Have you tested yet to see if what you ask will work?

If one has a lot of images to process they should learn ImageMagick and its many applications. Then learn enough 'bash scripting' ( for i in *.jpg; do echo $i; ???whatever???; done ) to step through a list of images.
 
Old 10-17-2004, 06:39 PM   #5
Forezt
Member
 
Registered: Jun 2003
Location: Aero-nomadic
Distribution: Debian (etch, PPC)
Posts: 80

Rep: Reputation: 15
I'm trying to resize a batch of photos with that script, but the file names have spaces in them, so I always get this error:

Let's say I'm trying to resize a photo called "China 6 001.jpg".

It will say "convert: Unable to open file (6)."

Is there a way that I can make this script ignore spaces or something?
 
Old 10-17-2004, 07:35 PM   #6
Dave Kelly
Member
 
Registered: Aug 2004
Location: Todd Mission Texas
Distribution: Linspire
Posts: 213

Rep: Reputation: 31
Eye (i) contains the name of your image. Try resizing that.

Please read the several manuals for the ImageMagick suite.
animate, display, identify, import, montage, mogrify, composit , convert, etc

And google search for a copy of this:

abs-guide-2.6.orig

Excellent tutoral on bash scripting.

Also please post the exact script you used that recieved the error.

Dave

Last edited by Dave Kelly; 10-17-2004 at 07:44 PM.
 
Old 10-17-2004, 08:27 PM   #7
Forezt
Member
 
Registered: Jun 2003
Location: Aero-nomadic
Distribution: Debian (etch, PPC)
Posts: 80

Rep: Reputation: 15
This is the exact script I used:

for i in "*.jpg"; do echo $i; convert -size 600x450 $i -resize 600x450 $i; done
 
Old 10-18-2004, 12:55 AM   #8
Dave Kelly
Member
 
Registered: Aug 2004
Location: Todd Mission Texas
Distribution: Linspire
Posts: 213

Rep: Reputation: 31
Hmmm! What prompted you to enclose *.jpg in quotation marks?
 
Old 10-18-2004, 06:10 PM   #9
Forezt
Member
 
Registered: Jun 2003
Location: Aero-nomadic
Distribution: Debian (etch, PPC)
Posts: 80

Rep: Reputation: 15
erm.... Whoops.

Actually, I tried it without them and it still give the same thing.
 
Old 10-18-2004, 07:09 PM   #10
wapcaplet
Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
To deal with those pesky spaces in the filenames (and to get that 50-pixel-height limitation you want), try this:

Code:
for i in *.jpg; do echo "$i"; convert "$i" -resize x50 "$i"; done
Note the quotation marks around the $i - that groups the filename into one piece so your shell doesn't think it's several separate arguments. AFAIK, you don't need the "-size" option for most images; only those in some kind of raw format that the program is unable to figure out a size for. The use of x50 tells convert to resize to 50 pixels in height, and scale the width accordingly.
 
Old 10-18-2004, 07:55 PM   #11
Dave Kelly
Member
 
Registered: Aug 2004
Location: Todd Mission Texas
Distribution: Linspire
Posts: 213

Rep: Reputation: 31
Resizing images quickly

Wapcaplets illustration works just fine.

Another question you ask was what to do about the spaces in the file name. In the tutoral on bash scripting is an illustration of changing the spaces to under-scores.

Also the following script renames files with spaces in the title.
Code:
#!/bin/bash
##take a command line parameter for a new file name.
##all images will have the same name and be numbered.
pname=$1
number=0
ONE=1

for filename in *.jpg
do
        let "number += 1"
        mv "$filename" "$pname-$number.jpg"
done

if [ "$number" -eq "$ONE" ]                 # For correct grammar.
then
        echo "$number file renamed."
else
        echo "$number files renamed."
fi
To create file names with spaces use this: # changename 1stword" "2ndword
To create file names without space use this: #changename filename
 
Old 10-23-2004, 06:04 PM   #12
Forezt
Member
 
Registered: Jun 2003
Location: Aero-nomadic
Distribution: Debian (etch, PPC)
Posts: 80

Rep: Reputation: 15
Thanks ALOT for these scripts!

They saved me alot of time. I was trying to resize about 1,500 pictures I had taken in China for my website's gallery, and this did the trick.

 
Old 10-23-2004, 06:41 PM   #13
Dave Kelly
Member
 
Registered: Aug 2004
Location: Todd Mission Texas
Distribution: Linspire
Posts: 213

Rep: Reputation: 31
Would you allow us to view the pictures when they are published?
 
  


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
resizing series of images (convert) wawosz Linux - General 4 04-16-2008 10:07 PM
Graphics program for resizing images needed? M$ISBS Linux - Software 4 11-28-2005 03:52 AM
Convert cd images to dvd images rcsuk Debian 2 07-11-2005 11:34 AM
Resizing Images in the GIMP batgranny Linux - Software 1 02-15-2005 11:38 AM
2.4.15 quickly comes out! taz.devil Linux - General 20 11-27-2001 05:12 PM


All times are GMT -5. The time now is 07:46 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration