Democratic Underground Latest Greatest Lobby Journals Search Options Help Login
Google

Batch Resizing of Images (Linux)

Printer-friendly format Printer-friendly format
Printer-friendly format Email this thread to a friend
Printer-friendly format Bookmark this thread
This topic is archived.
Home » Discuss » DU Groups » Computers & Internet » Computer Help and Support Group Donate to DU
 
RoyGBiv Donating Member (1000+ posts) Send PM | Profile | Ignore Sat May-26-07 09:58 PM
Original message
Batch Resizing of Images (Linux)
I want to share this because I just discovered a really simple way to do something I've been doing more manually for a long time.

I take pictures with my camera at maximum resolution, which gives me great images that are way too big to put on places like Photobucket. To share the pics more easily with friends I've picked representative pics and resized them with Gimp, using some of its batch conversion techniques. That makes things quite a bit easier (some basic principle as batch conversions with Photoshop or the like), but sometimes, ya just want to do the whole folder with out a lot of click and dragging and selecting, or even just having to start up a resource hog to do one thing ... whatever.

Gimp is, among other things, a front-end for a lot of command line tools, one of which is, simply enough, called convert. It does a LOT of things. Well, one thing I figured out I could do with it is write a simple script and would resize every image in a given directory to my typical 1024x768, also maintaining aspect ratio, which means if 1024x768 would squeeze the pic and make it look weird, convert gets as close to that as possible. Now, I knew about "convert" already, but I didn't realize how simple the script would be, so I made this with a text editor:

#!/bin/bash
mkdir resize
for img in `ls *.JPG`
do
convert -size 1024x768 $img ./resize/$img
done

I used the upper-case "JPG" because my camera adds extensions in upper-case.

Named that rsjpg.sh, put it in my ~/bin directory, made it executable, and now when I download a group of jpegs from my camera, I just cd to that directory, run this, and it creates a new directory with copies of all those pics, resized as I want them. Took less than 10 seconds just now to convert 61MB of images, not including transfer time from camera, and the resized files consume 14MB and are of a suitable size for uploading.

The script is a bit sloppy. I'll eventually make it check for the existence of the directory "resize" first, then expand it to look for .tif, .gif, .png, etc. and the upper-case equivalents. But, it was quick and dirty and does what I want quickly.

Just thought I'd share.

Printer Friendly | Permalink |  | Top
MyNameGoesHere Donating Member (1000+ posts) Send PM | Profile | Ignore Sun May-27-07 07:14 PM
Response to Original message
1. how does it look when you
upsize them? I may try this.
Printer Friendly | Permalink |  | Top
 
RoyGBiv Donating Member (1000+ posts) Send PM | Profile | Ignore Sun May-27-07 08:11 PM
Response to Reply #1
2. I've never done that ...

I imagine the same problems involved in increasing resolution on any digital image would still apply.

Printer Friendly | Permalink |  | Top
 
RoyGBiv Donating Member (1000+ posts) Send PM | Profile | Ignore Sun May-27-07 09:52 PM
Response to Reply #1
3. Works as expected ...

Which is to say how it looks when you increase the size depends in part on the quality of the image you start with and just how big you make it over its initial size.

If you're wanting to play with it, convert has tons of options. If aliasing occurs, there's an anti-aliasing option, for example.

http://www.imagemagick.org/script/command-line-options.php



Printer Friendly | Permalink |  | Top
 
FormerDittoHead Donating Member (1000+ posts) Send PM | Profile | Ignore Wed May-30-07 09:41 PM
Response to Original message
4. This didn't work for me in Fedora... this is what worked for me...
convert -resize 1024x768 -quality 75 $img ./resize/$img

Printer Friendly | Permalink |  | Top
 
Lowell Donating Member (1000+ posts) Send PM | Profile | Ignore Sun Jun-03-07 01:22 PM
Response to Original message
5. That sounds like a lot of work
I use digikam in Debian. It has a batch resize tool that will convert all photos in a folder in a matter of minutes.
Printer Friendly | Permalink |  | Top
 
hg4 Donating Member (77 posts) Send PM | Profile | Ignore Fri Jun-22-07 11:01 PM
Response to Original message
6. for img in *.JPG # also works.. but carefulw/r 2 spaces in name..
<just some shell scripting hints, if you like shell scripts>

The `ls *JPG` is not adding value, the shell globbing by itself works too,
ie just use:

for img in *.JPG

If your files have spaces (I know..I'm sure camera does not do this]
in their names, try:

find . -iname "*.jpg" |
while read img;
do convert -size 1024x768 "$img" "./resize/$img"
# double-quoting groups the filenames together as a single CLI args
# even for names w/spaces
done

For other scripts dealing w/ long lists of files that have spaces
or other difficult chars in their names, see the
"-print0", and "-0" switches in the man pages for
find and xargs respectively.

Thanks again for letting me know about 'convert'.
Printer Friendly | Permalink |  | Top
 
DU AdBot (1000+ posts) Click to send private message to this author Click to view 
this author's profile Click to add 
this author to your buddy list Click to add 
this author to your Ignore list Fri Jun 14th 2024, 08:45 PM
Response to Original message
Advertisements [?]
 Top

Home » Discuss » DU Groups » Computers & Internet » Computer Help and Support Group Donate to DU

Powered by DCForum+ Version 1.1 Copyright 1997-2002 DCScripts.com
Software has been extensively modified by the DU administrators


Important Notices: By participating on this discussion board, visitors agree to abide by the rules outlined on our Rules page. Messages posted on the Democratic Underground Discussion Forums are the opinions of the individuals who post them, and do not necessarily represent the opinions of Democratic Underground, LLC.

Home  |  Discussion Forums  |  Journals |  Store  |  Donate

About DU  |  Contact Us  |  Privacy Policy

Got a message for Democratic Underground? Click here to send us a message.

© 2001 - 2011 Democratic Underground, LLC