Batch resize your photos with Apple Script

Aug 14, 2009 by Samantha Halfon · 2 Comments ·
Filed under: Computing, Photography 

We usually take a lot of photos when traveling. After we return, the photos go through the following work fow:

  1. Copy the photos from the Compact Flash or SD cards to the computer.
  2. Sort/Edit them manually to keep only the greatest ones
  3. Archives the raw material (all the photos before editing) and the selected ones in a folder (which is later on backed up)
  4. Resize the selected photos for Internet sharing (with family and friends only on a private website)
  5. Select and tag some of the above photos for upload to Flickr.

We are probably not the only ones wanting to share photos with our non geeks mothers via a photo gallery online and the resizing step is usually necessary to make their browsing experience more comfortable. We use Simple PHP Gallery Manager for Internet sharing. I use an Apple Script to automatically resize the photos for the Internet Gallery (thanks to MacOsX Hints for sharing the code)

Simple PHP Gallery Manager

Simple PHP Gallery Manager

Batch resize photos Apple Script

The script is located in my Library/Scripts folder. To resize photos, I only have to select them in the Finder and drag them on the script file. The script will then generate an image called export_<Name_of_the_original>.jpg for each selected photo. Of course, Apple Script is Mac only. I have a similar script for Windows/Linux laying around (based on nconvert). If interested, please leave us a comment and I’ll post a follow up to this article.

The interest of Apple Script resides in its ability to pilot other applications (like the Finder in the following example) to automate tasks (in the same way as Photoshop tasks). And the power of the Apple Script Editor is the ability to record what we are doing and turn that into a script (using Automator for example).

The code

on open some_items
repeat with this_item in some_items
try
rescale_and_save(this_item)
end try
end repeat
end open
to rescale_and_save(this_item)
tell application “Image Events”
launch
set the target_height to 600
– open the image file
set this_image to open this_item
set typ to this_image’s file type
copy dimensions of this_image to {current_width, current_height}
if current_height is greater than current_width then
scale this_image to size target_height
else
– figure out new height
– y2 = (y1 * x2) / x1
set the new_width to (current_width * target_height) / current_height
scale this_image to size new_width
end if
tell application “Finder” to set new_item to ¬
(container of this_item as string) & “ex” & (name of this_item)
save this_image in new_item as typ
end tell
end rescale_and_save

Use the script

  1. Open Script Editor (in Application or using Spotlight)
  2. Copy/Paste the code in the editor
  3. Edit the target_height variable to whatever you need (in pixels)
  4. Save the script to your Library/Scripts folder

Download

The script is available for download.

Thumbnails

Some Internet gallery (inclusing SPGM) also need a thumbnail file. It is of course possible to modify this script to generate two pictures (one for display, one as thumbnail) for each selected photo.

Apple Script

Apple scripting allows you to automate most recurring tasks and customize your Mac OS X experience. I’ve recently spanned through an Apple Script Book I got at our local library called “The Missing Guide“, it seems very powerful. For more information on Apple Script, check out there resources:

First time on World Wide Angle, you may want to subscribe to our RSS feed. Thanks for visiting!


 

 

Comments

2 Responses to “Batch resize your photos with Apple Script”

Trackbacks

Check out what others are saying about this post...
  1. worldwideangle says:

    New Blog Post: Batch resize your photos with Apple Script http://bit.ly/Mn0nt

  2. New Blog Post: Batch resize your photos with Apple Script http://bit.ly/Mn0nt



Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!