Sunday, April 30, 2017

#1 2016-12-16 02:38:36 am

Maximka
Member
Registered: 2016-12-03
Posts: 7

Image orientation

Hi!
Is there a script to determine image orientation?

Like:
1. Normal
2. Flipped Horizontally
3. Rotated 180
4. Flipped Vertically
5. Rotated 90 clockwise, then flipped horizontally
6. Rotated 90 anticlockwise
7. Rotated 90 anticlockwise, then flipped horizontally
8. Rotate 90 clockwise

Offline

 

#2 2016-12-16 03:38:11 pm

t.spoon
Member
From: BFE, Massachusetts
Registered: 2013-01-12
Posts: 130

Re: Image orientation

We need more to go on to understand what you're asking. Are you asking for access to an attribute tag that has that information? Or are you asking for the computer to recognize the image contents and discern the proper orientation, including things like mirroring, like a human could attempt to do? Basically, strong AI?

Offline

 

#3 2017-01-11 01:57:00 am

Maximka
Member
Registered: 2016-12-03
Posts: 7

Re: Image orientation

I have a script that convert any image to widescreen:

Applescript:

on run {input, parameters}
   repeat with this_file in input
       set this_file to (this_file as text)
       tell application "Image Events"
           -- start the Image Events application
           launch
           -- open the image file
           set this_image to open this_file
           -- get dimensions of the image
           copy dimensions of this_image to {W, H}
           -- determine the letterbox area
           set crop_W to W
           -- calcluate the 16:9 proportions
           set crop_H to (W * 9) / 16
           -- perform action
           crop this_image to dimensions {crop_W, crop_H}
           -- save the changes
           save this_image with icon
           -- purge the open image data
           
       end tell
       
   end repeat
end run

And I want this script to skip vertical orientation by dimension and by EXIF tags like: Flipped Horizontally, Rotated etc.
So this script will process only horizontal images...

Offline

 

#4 2017-01-12 09:02:24 am

t.spoon
Member
From: BFE, Massachusetts
Registered: 2013-01-12
Posts: 130

Re: Image orientation

Simply restricting it to only acting on images in landscape orientation is certainly easy. I haven't looked into the EXIF tags yet.

Applescript:

on run {input, parameters}
   repeat with this_file in input
       set this_file to (this_file as text)
       tell application "Image Events"
           -- start the Image Events application
           launch
           -- open the image file
           set this_image to open this_file
           -- get dimensions of the image
           copy dimensions of this_image to {W, H}
           -- only act on landscape image
           if W > H then
               -- determine the letterbox area
               set crop_W to W
               -- calcluate the 16:9 proportions
               set crop_H to (W * 9) / 16
               -- perform action
               crop this_image to dimensions {crop_W, crop_H}
               -- save the changes
               save this_image with icon
               -- purge the open image data
           end if
       end tell
   end repeat
end run

Offline

 

#5 2017-01-13 06:34:28 am

Nigel Garvey
Moderator
From: Warwickshire, England
Registered: 2002-11-19
Posts: 4265

Re: Image orientation

t.spoon wrote:

I haven't looked into the EXIF tags yet.

I don't think EXIF is what's meant. The numbers in post #1 correspond to those shown in the "General" and "TIFF" tabs of Preview's Inspector window when the orientation of a displayed image is changed. If the image is saved with a new orientation, that becomes the new "1 (normal)" when the image is opened again.


NG

Offline

 

#6 2017-01-13 07:36:01 am

t.spoon
Member
From: BFE, Massachusetts
Registered: 2013-01-12
Posts: 130

Re: Image orientation

Ah. I hadn't recognized those as being from a particular type of tag, I thought it was just a list of possibilities he was trying to recognize.

So it sounds like he wants to skip portrait orientation, but simply skipping based on h>w would miss images that are only portrait because they are tagged to display in a different orientation than the the default pixel order.

Sounds easy enough, I'll take a look at accessing those tags when I have a chance.

- Tom.

Offline

 

#7 2017-01-15 05:58:40 am

Maximka
Member
Registered: 2016-12-03
Posts: 7

Re: Image orientation

t.spoon wrote:

Ah. I hadn't recognized those as being from a particular type of tag, I thought it was just a list of possibilities he was trying to recognize.

So it sounds like he wants to skip portrait orientation, but simply skipping based on h>w would miss images that are only portrait because they are tagged to display in a different orientation than the the default pixel order.

Sounds easy enough, I'll take a look at accessing those tags when I have a chance.

- Tom.

Yeah, you right. Thanks in advance...

Offline

 

#8 2017-01-19 10:35:29 am

t.spoon
Member
From: BFE, Massachusetts
Registered: 2013-01-12
Posts: 130

Re: Image orientation

I haven't had a chance to do any testing yet, but I think this should get you close:

Applescript:

on run {input, parameters}
   repeat with currentFile in input
       set posixFilePath to the quoted form of (POSIX path of currentFile)
       set orientationFlag to (do shell script "mdls " & theFile & " -name kMDItemOrientation")
       set theOrientation to text ((offset of "= " in orientationFlag) + 2) through end of orientationFlag as number
       set currentFile to (currentFile as text)
       set rotatedOrientations to "5,6,7,8"
       tell application "Image Events"
           -- start the Image Events application
           launch
           -- open the image file
           set thisImage to open currentFile
           -- get dimensions of the image
           copy dimensions of thisImage to {W, H}
           -- only act on landscape image
           set cropIt to false
           if theOrientation is not in rotatedOrientations then
               if W > H then
                   set cropIt to true
                   -- determine the letterbox area
                   set cropW to W
                   -- calcluate the 16:9 proportions
                   set cropH to (W * 9) / 16
               end if
           else if theOrientation is in rotatedOrientations then
               if H > W then
                   set cropIt to true
                   set cropW to H * 9 / 16
                   set cropH to H
               end if
               -- perform action
               if cropIt is true then
                   crop thisImage to dimensions {cropW, cropH}
                   -- save the changes
                   save thisImage with icon
               end if
               -- purge the open image data
           end if
       end tell
   end repeat
end run

Offline

 

#9 2017-02-02 01:33:29 pm

Maximka
Member
Registered: 2016-12-03
Posts: 7

Re: Image orientation

Thanks, but get an error:

The action “Run AppleScript” encountered an error.

Offline

 

#10 2017-02-02 01:52:32 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 2959

Re: Image orientation

Try to edit the instruction :

Applescript:

set posixFilePath to the quoted form of (POSIX path of currentFile)

as

Applescript:

set theFile to the quoted form of (POSIX path of currentFile)

Yvan KOENIG running Sierra 10.12.3 in French (VALLAURIS, France) jeudi 2 février 2017 20:52:25

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.079 seconds, 8 queries executed ]

RSS (new topics) RSS (active topics)