Script programing (Python)

Moderator: Kathy_9

Post Reply
Remo
Posts: 2
Joined: Mon Jun 23, 2014 10:38 pm
operating_system: Windows 7 Professional
System_Drive: C

Script programing (Python)

Post by Remo »

Hello

When I open a picture taken by my digital camera in "portrait mode" (but not "landscape mode"), Paint Shop Pro X rotates the Picture by 90°automaticly in the first moment. I would like to write a python script that turns and saves all my pictures in "portrait mode". Is that possible? Windows shows a EXIF variable "Exposure program" that is equal to portrait mode or landscape mode. But what is the correct if-statement in Python? I tryed

def Do(Environment):
if 'Exposure program' == "landscape mode":
...

but that doesn't work. Every hint would be appreciated.

Remo
LeviFiction
Advisor
Posts: 6831
Joined: Thu Oct 02, 2008 1:07 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Alienware M17xR4
processor: Intel Core i7-3630QM CPU - 2_40GH
ram: 6 GB
Video Card: NVIDIA GeForce GTX 660M
sound_card: Sound Blaster Recon3Di
Hard_Drive_Capacity: 500GB
Corel programs: PSP: 8-2023
Location: USA

Re: Script programing (Python)

Post by LeviFiction »

Well, you could just compare the width to the height. Since portrait will be taller than wide.

Code: Select all

if App.TargetDocument.Width > App.TargetDocument.Height:
    #In Landscape
    #Command to rotate 90 degrees here

#Command to Save here
If you want to grab the EXIF information you need to call ReturnImageInfo and grab a specific item from the list.

Code: Select all

ImageInfo = App.Do( Environment, "ReturnImageInfo", {})

if ImageInfo['ExifExposureProgram'].lower() == "landscape mode":
    #In Landscape
    #Command to rotate 90 degrees here
I used .lower() in this code in case there is ever a photo with "Landscape Mode" or "LANDSCAPE MODE" in it. It forces the casing of the letters to all be lower case when comparing to "landscape mode" it may be unnecessary but it's just a precaution.
https://levifiction.wordpress.com/
Remo
Posts: 2
Joined: Mon Jun 23, 2014 10:38 pm
operating_system: Windows 7 Professional
System_Drive: C

Re: Script programing (Python)

Post by Remo »

Hello LeviFiction

Thanks for your quick answer. The first method doesn't work, because all Pictures (landscape and portrait mode) have the same width and height. But with your second hint, I managed to do what I want :D . Thank you again.

Remo, Switzerland
Post Reply