[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ale] batch image resizing

I do batch image processing frequently using the ImageMagick
command line tools on my Mac OSeX systems (with thanks to
the Fink project for making the OSS ports like ImageMagick
available and easy to install).

The "mogrify" function can make various modifications directly
to the existing image file.  The scaling function is  "-geometry" (or its 
alias "-resize").

If you want a specific Y size of 1280 while auto-Magick-aly scaling
X to maintain the aspect ratio, I  believe the command would be:

%>    mogrify -geometry x1280 "my_image_file.jpg"

The command accepts multiple file names and shell globbing,
so you can easily do a whole directory at a time:

%>    mogrify -resize x1280 "my_image_dir/*.jpg"

>From the ImageMagick man page:

-geometry <width>x<height>{+-}<x>{+-}<y>{%}{@} {!}{<}{>}
              preferred size and location of the Image window.

  By default, the window size is the image size and the location is
chosen by you when it is mapped.
  By  default,  the  width and height are maximum values. That is, the image 
is expanded or contracted to fitthe width and height value while maintaining 
the aspect ratio of the image.
  Append an exclamation point  to the  geometry to force the image size to 
exactly the size you specify. For example, if you specify 640x480!
the image width is set to 640 pixels and height to 480.

  If only the width is specified, the width assumes the value and the height 
is chosen to maintain the aspect ratio of the image.  Similarly, if only the 
height is specified (e.g., -geometry x256), the width is chosen to maintain
the aspect ratio.


Hope that helps!
 (-: The rest of the script processes I'll leave to you... :-)


On Tuesday 10 April 2007 16:35, Preston Boyington wrote:
> yep, it's me again.  i have been using a "comic book reader" style for
> my zipped jpgs and now i want to resize the images in the zip files to a
> smaller resolution.
> if you are not familiar with cbr (or cbz) files, they are just zipped
> (cbz) or rar'ed (cbr) files of images with the extension changed so they
> open with Comix (for Linux) or CDisplay (Windows).  I have come to use
> this style for pictures that I send to family and friends.  this way
> they don't have to unzip the file and then go to the directory and then
> open their image viewer to see them.  all they have to do is double
> click on the cbr (or cbz) file and the viewer starts up for them to page
> through the images.  this has made things much simpler for me when
> dealing with certain people.
> since i have several years worth of zipped files, i was hoping to do the
> following (possibly) with a shell script:
> 1) rename the file (which probably has spaces in the name) to either zip
> or rar (depending on cbZ or cbR extension)
> 2) unzip/unrar the file
> 3) resize all files in the created directory so that their height is
> 1280px (keeping the ratio.  don't care how wide the images turn out to
> be just want the height to be "Whatever x 1280")
> 4) zip the files back up
> 5) rename to cbz extension (since i think it will be easier to zip than rar)
> 6) delete the created directory and start on the next file
> i am hoping that i will be able to lessen the file sizes by almost half
> without losing much of the clarity in the pictures (car shows,
> motorcycle shows, birthday parties, etc) by doing all this.
> i have found a command in the ImageMagick suite called "mogrify" which i
> think might fit my needs, although i am unsure of how to keep the width
> "open" so that my ratio's don't get whacked.  some of these pictures
> have been oddly cropped so they are "taller" than "wide"
> so while i am researching the 'net, i thought maybe someone might have
> done something similar to this already.  i really don't want to have to
> manually go through all these gigs worth of pictures in my spare time.
> as always, any suggestions are appreciated.
> Preston
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale