iPhoto - Script to automate rotation

Hi,

Total newbie here…I’m thinking about playing with AppleScript. One common problem that I have is that I need to rotate pictures more than 90 degrees. I’m an iPhoto novice, but in my limited usage it seems that I have to click the rotate button 2, 3, or 4 times to rotate the image to its final state.

I would like to write an AppleScript that would include a GUI that would prompt the user for how many degrees to rotate and in which direction (clockwise or counter clockwise).

I looked at the iPhoto script docs and it doesn’t seem that I can rotate an image. Seems like only file type operations were available.

I was hoping that AppleScript would be similar to Microsoft VBA where I can “record” actions in an application and then modify the generated code.

I have read that Panther now provides some image manipulation on an OS level. Is that correct?

So, can I use iPhoto-only functions to do this? If not, can I use a combo of iPhoto and Panther functions? But I guess then I’d have to find the exact file of a photo in the iPhoto library…Is that easy to do?

Thanks,
Brian

try using image capture scripting

display dialog "what angle would you like" default answer "-90"
set the_angle to the text returned of the result

set the_file to choose file
tell application "Image Capture Scripting"
	set this_image to open the_file
	rotate this_image to angle (the_angle as number)
	save this_image in the_file
	close this_image
end tell

of course you may need some error handling 
but this could do the trick

I pieced together snippets of code from various places and with the help of others in this forum (Rob mainly) i put together a script at the folowing post
http://bbs.applescript.net/viewtopic.php?p=21863#21863

global the_angle
on run
set thefolder to (choose folder)
tell application “Finder” to ¬
set these_items to items of thefolder as alias list
[color=green]process_all/color
end run

on open these_items
[color=green]process_all/color
end open

on [color=green]process_all/color
=========== Use this set to control rotation globally===========

 [color=blue]display dialog[/color] "What angle would you like for files?" & [color=blue]return[/color] & "use - for counter clockwise" [color=blue]default answer[/color] "-90"
 [color=blue]set[/color] [color=green]the_angle[/color] [color=blue]to[/color] [color=blue]the[/color] [color=blue]text returned[/color] [color=blue]of[/color] [color=blue]the[/color] [color=blue]result[/color]
 
 --[color=olive] ======== end global control ===============[/color]
 
 [color=blue]repeat[/color] [color=blue]with[/color] [color=green]i[/color] [color=blue]from[/color] 1 [color=blue]to[/color] [color=blue]the[/color] [color=blue]count[/color] [color=blue]of[/color] [color=green]items_[/color]
      [color=blue]set[/color] [color=green]this_item[/color] [color=blue]to[/color] ([color=blue]item[/color] [color=green]i[/color] [color=blue]of[/color] [color=green]items_[/color])
      [color=blue]set[/color] [color=blue]the[/color] [color=green]item_info[/color] [color=blue]to[/color] [color=blue]info for[/color] [color=green]this_item[/color]
      [color=blue]if[/color] [color=blue]folder[/color] [color=blue]of[/color] [color=blue]the[/color] [color=green]item_info[/color] [color=blue]is[/color] [color=blue]true[/color] [color=blue]then[/color]
           [color=green]process_folder[/color]([color=green]this_item[/color])
      [color=blue]else[/color] [color=blue]if[/color] ([color=blue]alias[/color] [color=blue]of[/color] [color=blue]the[/color] [color=green]item_info[/color] [color=blue]is[/color] [color=blue]false[/color]) [color=blue]then[/color]
           [color=blue]my[/color] [color=green]process_item[/color]([color=green]this_item[/color])
      [color=blue]end[/color] [color=blue]if[/color]
 [color=blue]end[/color] [color=blue]repeat[/color]

end process_all

this sub-routine processes folders
on [color=green]process_folder/color
tell application “Finder” to ¬
set these_items to items of folder this_folder as alias list
repeat with i from 1 to the count of these_items
set this_item to item i of these_items
set the item_info to info for this_item
if folder of the item_info is true then
[color=green]process_folder/color
else if (alias of the item_info is false) then
my [color=green]process_item/color
end if
end repeat
end process_folder

this sub-routine rotates the files
on [color=green]process_item/color

 (*[color=olive]--============ use these to control each file's angle individually=========

set the_info to info for this_item
display dialog “What angle would you like for file” & return & ((name of the_info) as text) & return & “use - for counter clockwise” default answer “-90”
set the_angle to the text returned of the result

–========== end individual angle control=============
[/color]*)

 [color=blue]tell[/color] [color=blue]application[/color] "Image Capture Scripting"
      [color=blue]set[/color] [color=green]this_image[/color] [color=blue]to[/color] [color=blue]open[/color] [color=green]this_item[/color]
      [color=blue]rotate[/color] [color=green]this_image[/color] [color=blue]to angle[/color] ([color=green]the_angle[/color] [color=blue]as[/color] [color=blue]number[/color])
      [color=blue]save[/color] [color=green]this_image[/color] [color=blue]in[/color] [color=green]this_item[/color]
      [color=blue]close[/color] [color=green]this_image[/color]
 [color=blue]end[/color] [color=blue]tell[/color]

end process_item

this script was automatically tagged for
color coded syntax by Script to Markup Code
written by Jonathan Nathan

Greetings,
The discussion above is along similar lines to what I was considering how to address. With my digital camera (Olympus C-750 UltraZoom) you can rotate images during playback on the camera. When these images are imported by Image Capture, they are in their original orientation, not rotated. However, the EXIF data in the picture is updated by the camera, to say:

Orientation: Rotate 90

I manually go through when importing images and rotate them in Image Capture anyway, but was thinking it would be excellent if Image Capture automatically rotated any images that had this EXIF data. Looking at Image Capture more I’ve realised that while you can set it to run an Applescript after downloading images, I would have already rotated them manually by then anyway.

Hmm. I think what I want should be included in Image Capture automatically, and probably can’t be fixed by an AppleScript. Any ideas though? And, is this changed in Panther? (Haven’t yet upgraded, though going to soon!)

Cheers,
Duncan.

sigamy,
Unless you frequently take pics with your camera upside down, you really should never need to click the rotate button in iPhoto more than once. (Even if you do take pics upside down, you would only need to click rotate twice!) The direction of rotation can be changed by holding down the option key. You can also set the default rotation direction of this button in iPhoto’s prefs. So if you usually hold your camera with the left side down, you can set the default rotation direction to suit that. If you have a photo that you need to rotate the direction opposite of your default direction, just hold the option key and click it. BTW, clicking rotate 4 times results in the photo being in it’s original orientation. :wink:
HTH.

Duncan,

You mentioned that you camera inserts exif information which includes the rotation of the camera when the picture was taken. I am in the processing of finalizing the features for version 2 of iMagine which will be due out in February. I have greatly extended the exif functionality for reading and writing exif information for AppleScripters but I haven’t got any images which have the orientation specified in the exif information. I would greatly appreciate it if you could supply me with an image file so that I can add orientation as one of the exif parameters that I can read and write.

Kevin

Kevin,
No problem. See your email for details on where to download the images.
Cheers,
Duncan.