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 |
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
10-11-2004, 04:59 PM
|
#1
|
Member
Registered: Sep 2004
Distribution: Debian 4.0, Ubuntu 6.10, Ubuntu Server 6.06
Posts: 134
Rep:
|
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
|
|
|
10-11-2004, 05:11 PM
|
#2
|
Member
Registered: Aug 2004
Location: Todd Mission Texas
Distribution: Linspire
Posts: 215
Rep:
|
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.
|
|
|
10-11-2004, 05:27 PM
|
#3
|
Member
Registered: Sep 2004
Distribution: Arch :D
Posts: 66
Rep:
|
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.
|
|
|
10-11-2004, 06:55 PM
|
#4
|
Member
Registered: Aug 2004
Location: Todd Mission Texas
Distribution: Linspire
Posts: 215
Rep:
|
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.
|
|
|
10-17-2004, 05:39 PM
|
#5
|
Member
Registered: Jun 2003
Location: Aero-nomadic
Distribution: Debian (etch, PPC)
Posts: 80
Rep:
|
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?
|
|
|
10-17-2004, 06:35 PM
|
#6
|
Member
Registered: Aug 2004
Location: Todd Mission Texas
Distribution: Linspire
Posts: 215
Rep:
|
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 06:44 PM.
|
|
|
10-17-2004, 07:27 PM
|
#7
|
Member
Registered: Jun 2003
Location: Aero-nomadic
Distribution: Debian (etch, PPC)
Posts: 80
Rep:
|
This is the exact script I used:
for i in "*.jpg"; do echo $i; convert -size 600x450 $i -resize 600x450 $i; done
|
|
|
10-17-2004, 11:55 PM
|
#8
|
Member
Registered: Aug 2004
Location: Todd Mission Texas
Distribution: Linspire
Posts: 215
Rep:
|
Hmmm! What prompted you to enclose *.jpg in quotation marks?
|
|
|
10-18-2004, 05:10 PM
|
#9
|
Member
Registered: Jun 2003
Location: Aero-nomadic
Distribution: Debian (etch, PPC)
Posts: 80
Rep:
|
erm.... Whoops.
Actually, I tried it without them and it still give the same thing.
|
|
|
10-18-2004, 06:09 PM
|
#10
|
LQ Guru
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018
Rep:
|
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.
|
|
|
10-18-2004, 06:55 PM
|
#11
|
Member
Registered: Aug 2004
Location: Todd Mission Texas
Distribution: Linspire
Posts: 215
Rep:
|
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
|
|
|
10-23-2004, 05:04 PM
|
#12
|
Member
Registered: Jun 2003
Location: Aero-nomadic
Distribution: Debian (etch, PPC)
Posts: 80
Rep:
|
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.

|
|
|
10-23-2004, 05:41 PM
|
#13
|
Member
Registered: Aug 2004
Location: Todd Mission Texas
Distribution: Linspire
Posts: 215
Rep:
|
Would you allow us to view the pictures when they are published?
|
|
|
All times are GMT -5. The time now is 12:41 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
|
|