Agile FAQs
  About   Slides   Home  

 
Managed Chaos
Naresh Jain's Random Thoughts on Software Development and Adventure Sports
     
`
 
RSS Feed
Recent Thoughts
Tags
Recent Comments

Using AppleScript to Programmatically Crop Images

Create the following AppleScript using the AppleScript Editor

on run argv
  set the this_file to item 1 of argv
  set the vertical_crop to 20
  set the horizontal_crop to 30
  tell application "Image Events"
    launch
    set this_image to open this_file
    copy dimensions of this_image to {W, H}
    crop this_image to dimensions {W - horizontal_crop, H - vertical_crop}
    save this_image with icon
    close this_image
  end tell
end run

Compile and save the file as a script.

save script dialog

Now you are ready to run the script on your images:

naresh$ osascript crop_image.scpt /complete/path/to/image.ext

Results:

Before After
original image cropped image

    Licensed under
Creative Commons License