Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Rotate an image using a drag and drop AppleScript Apps
I found the Drag-and-drop script to quickly resize any image hint a while back, and found it exceedingly helpful; I use it all the time for resizing. I thought about making something just as easy, to handle rotating images, would be awesome. Here's what I came up with:
-- Slight rehashing of this tutorial: http://www.macosxhints.com/article.php?story=2004092804461334
-- Thanks for the kickstart "robg."

on open some_items
  repeat with this_item in some_items
    try
      rotate_and_save(this_item)
    end try
  end repeat
end open

to rotate_and_save(this_item)
  
  tell application "Image Events"
    launch
    -- open the image file
    set this_image to open this_item
    set typ to this_image's file type
    rotate this_image to angle 90
    -- Feel free to change the "90" to however many degrees you want to rotate
  end tell
  
  tell application "Finder" to set new_item to 
    (container of this_item as string) & "rotated90." & (name of this_item)
  -- You can also change the "rotate90." to whatever you want added onto the beginning of the new file name.
  save this_image in new_item as typ
end rotate_and_save
Open up Script Editor, start a new script, and paste in the above code. Now just save it in application format, and you're good to go. Hope this helps somebody.

[robg adds: Read the rest of the hint for a variation on this from queue reviewer mark hunte. His version prompts for the direction of rotation (left, right, 180), instead of being hardcoded to 90 degrees.]

Here's Mark's version:
-- Slight rehashing of this tutorial: http://www.macosxhints.com/article.php?story=2004092804461334
-- Thanks for the kickstart "robg."
global theAngle
on open some_items
  display dialog "Rotate...?" buttons {"Left", "Right", "180"} default button 3
  set the button_pressed to the button returned of the result
  if the button_pressed is "Left" then
    set theAngle to 270
  else if the button_pressed is "Right" then
    set theAngle to 90
  else if the button_pressed is "180" then
    set theAngle to 180
  end if
  repeat with this_item in some_items
    try
      rotate_and_save(this_item, theAngle, button_pressed)
    end try
  end repeat
end open

to rotate_and_save(this_item, theAngle, button_pressed)
  
  tell application "Image Events"
    launch
    -- open the image file
    set this_image to open this_item
    set typ to this_image's file type
    rotate this_image to angle theAngle
    -- Feel free to change the "90" to however many degrees you want to rotate
  end tell
  
  tell application "Finder" to set new_item to 
    (container of this_item as string) & "rotated_" & button_pressed & "_" & (name of this_item)
  
  save this_image in new_item as typ
end rotate_and_save
These both worked as described in my testing.
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[8,082 views]  

Rotate an image using a drag and drop AppleScript | 4 comments | Create New Account
Click here to return to the 'Rotate an image using a drag and drop AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
command line solution: jhead
Authored by: LouieNet on Dec 16, '07 12:32:57AM
I'd like to mention the command line solution that I often use: jhead. The autorot flag will "invoke jpegtran to rotate images according to Exif orientation tag".

Of course, this assumes that the file has Exif information that says what the orientation should be. My Canon camera puts that information into the photos files.

---
G4 cube, 17" Powerbook G4, iMac 20", Mac mini, PowerMac 7500 (w/ G4 upgrade card)

[ Reply to This | # ]

Rotate an image using a drag and drop AppleScript
Authored by: robogobo on Dec 18, '07 05:04:13PM

Automator also has a useful finder item that opens a dialog for 180 degrees, or 90 Left/Right, and (not really) preview. This can be placed in the Automator contextual menu. I use it all the time.

On a side note, can anyone briefly explain why some apps respect this kind of rotate while others don't? I'm sure it has something to do with tags vs byte order, but how can you tell?



[ Reply to This | # ]
Rotate an image using a drag and drop AppleScript
Authored by: DeltaTee on Dec 18, '07 05:25:13PM

I assume that Automator doesn't change the image data, but rather just changes the tag which describes the rotation that should be performed. Some applications use this tag and some don't.



[ Reply to This | # ]
Rotate an image using a drag and drop AppleScript
Authored by: robogobo on Dec 19, '07 01:03:50PM

In 10.4 it did just change the tag, but I think in 10.5 it actually changes the byte order. I'm not sure because I don't know how to which one a particular app is looking at. That's the confusion. I think the real test happens when I upload to a server in order to post an image on a php board, but even then I'm not sure if the tag is respected or not.



[ Reply to This | # ]