Using Image Events and Applescript to Resize your Images

Image Events is a background application that can do stuff to your images. Applescript is a scripting language for the Mac OS. For the purposes of this blog we are going to resize a folder of images and save them to different locations.

I have a regular job that I do where the client needs the finished images in 3 resolutions. 2048px, 1300px, and 177px saved to 3 seperate folders. This of course can be done in Lr but the advantage of Image Events is that it works in the background and does not hog you time using Lr. It’s also quicker.

Open Utilities:Script Editor: and create a new document.

Lets first put some property values in. These values are constant throughout the script and you can replace the integers (denoting pixel size) with your own if you wish.

property Big : 2048
property Medium:1300
property Small:177

Now lets write the handler. This is going to do all the processing using Image Events as the application.

on resizeiamge(this_item, theResize, destfolder)
set theJPG to name of (info for this_item)
tell application "Image Events"
launch
set this_image to open this_item --resize the image
scale this_image to size theResize
save this_image in file (destfolder & theJPG as string) as JPEG
close this_image
end tell
end resizeiamge

This handler is given 3 variables. (this_item, theResize, destfolder) or The Image, Resize Size and Destination Folder.

Create a folder somewhere and add 3 folders inside itblog.jpg

create a {list} of those folders in Applescript with the code.

set theFolders to {"Big", "Medium", "Small"}

An list in Applescript looks like this {item 1, item2, item 3…..}

Now we have to tell your script where the images are that you want to process and where you have just created those folders.

set originalImages to choose folder with prompt "Choose original image folder"
set processfolder to choose folder with prompt "Where do you want to them saved?"

Because you have to process the images 3 times you need to loop the script 3 times to achieve this. So….

Get all the images in the original image folder as a list of addresses ie alias yourharddrive:user:you:pictures:originals:12345.jpg

tell application "Finder"

 set allimages to get every file of folder originalImages as alias list

end tell

--and then create your repeat loop

repeat with i from 1 to number of items in allimages
set this_item to item i of allimages

end repeat

What this does is get items 1,2,3,4 etc of the list in turn and process it.

Ok lets call the handler in

repeat with i from 1 to number of items in allimages
set this_item to item i of allimages
resizeiamge(this_item, Big, processfolder & item 1 of theFolders)
resizeiamge(this_item, Medium, processfolder & item 2 of theFolders)
resizeiamge(this_item, Small, processfolder & item 3 of theFolders)
end repeat

This action calls the handler and passes the variables to it ie.

this_item - the image address
Big, Medium, Small - the resize size
The destination folder (coerced to a string in the handler)

Save the script as a script or application and run it.

scr.jpg

For workflow and photography workshops click here

 

 

 

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.