Resize depending on landscape or portrait mode?

Moderator: Kathy_9

Post Reply
pstein
Posts: 73
Joined: Wed Dec 28, 2011 7:09 pm
operating_system: Windows 7 Professional
System_Drive: C
32bit or 64bit: 64 Bit
Corel programs: PSP X2
Location: Germany/Canada

Resize depending on landscape or portrait mode?

Post by pstein »

Assume I have a folder with lots (> 800) of photos.
Most of them are in landscape mode but some of them are in portrait mode.

For a web album I want to resize them to a lower resolution.
So I can record a script and with a resize operation to 1920 x 1440 pixel size

Unfortunately when I run this script in batch mode onto the full photo file directory ALL photos are resized.
...even those which are in portrait mode.

:-(

How can I setup a resize operation in a script which acts in a more smarter way depending on the mode:

1) If photo is in landscape mode (=width > height) --->resize to 1920 x 1440 pixel
2) If photo is in portrait mode (=height > width) --->resize to 1440 x 1920 pixel

?

Peter
LeviFiction
Advisor
Posts: 5984
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, 9, X, XI, X2, X8,X9, 2018, 2019
Location: USA

Re: Resize depending on landscape or portrait mode?

Post by LeviFiction »

Are they all the correct aspect ratio to get 1440 on the short side if you resize the long side to 1920? If so then you don't need scripting. The batch process command let's you add a resize function to the batch. The resize command has an option to resize by one side, the longest or shortest. Add that to the batch to do the resize.

Otherwise to do this in a script you need an if else statement and need to use the variables App.TargetDocument.Width and App.TargetDocument.Height
pstein
Posts: 73
Joined: Wed Dec 28, 2011 7:09 pm
operating_system: Windows 7 Professional
System_Drive: C
32bit or 64bit: 64 Bit
Corel programs: PSP X2
Location: Germany/Canada

Re: Resize depending on landscape or portrait mode?

Post by pstein »

LeviFiction wrote:The resize command has an option to resize by one side, the longest or shortest. Add that to the batch to do the resize.
Hmm, where is this option in the resize dialog? I don't find it (see attached snapshot).
If I have to add it manually in script text file: How should the full command look like?
LeviFiction wrote: Otherwise to do this in a script you need an if else statement and need to use the variables App.TargetDocument.Width and App.TargetDocument.Height
Sorry, I am a PSP scripting newbie:

How would such an if-else command look like in detail?
The following does not work:

If App.TargetDocument.Width > App.TargetDocument.Height (
App.Do( Environment, 'Resize', {
'AspectRatio': 1.33333,
'CurrentDimensionUnits': App.Constants.UnitsOfMeasure.Pixels,
'CurrentResolutionUnits': App.Constants.ResolutionUnits.PixelsPerIn,
'Height': 1440,
'MaintainAspectRatio': True,
'Resample': True,
'ResampleType': App.Constants.ResampleType.Bicubic,
'ResizeAllLayers': True,
'Resolution': 300,
'Width': 1920,
'SharpnessValue': 50,
'AdvancedMode': True,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((12,0,1),1)
}
})
) else (
App.Do( Environment, 'Resize', {
'AspectRatio': 1.33333,
'CurrentDimensionUnits': App.Constants.UnitsOfMeasure.Pixels,
'CurrentResolutionUnits': App.Constants.ResolutionUnits.PixelsPerIn,
'Height': 1920,
'MaintainAspectRatio': True,
'Resample': True,
'ResampleType': App.Constants.ResampleType.Bicubic,
'ResizeAllLayers': True,
'Resolution': 300,
'Width': 1440,
'SharpnessValue': 50,
'AdvancedMode': True,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((12,0,1),1)
}
})
)
Attachments
Resize dialog.png
LeviFiction
Advisor
Posts: 5984
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, 9, X, XI, X2, X8,X9, 2018, 2019
Location: USA

Re: Resize depending on landscape or portrait mode?

Post by LeviFiction »

My apologies I didn't realize you were running an older version of PSP.

Newer versions support the resize by one side.

PSP uses the Python programming language to make its scripts. There are hundreds of resources if you want to get into making smarter scripts than just the ones recorded by PSP. One of the most important things is Python uses whitespace not parentheses or brackets to enclose code blocks.

Also, you can shrink your code considerably by using variables to hold the new width and height values and then calling the Resize command using those variables. Here is an example code:

Code: Select all

def Do(Environment):
    width = 1920 #Start off with a presumption of landscape
    height = 1440
    if App.TargetDocument.Width > App.TargetDocument.Height:
        width = 1440 #if not landscape, switch to portrait
        height = 1920

    App.Do( Environment, 'Resize', {
        'AspectRatio': 1.33333, 
        'CurrentDimensionUnits': App.Constants.UnitsOfMeasure.Pixels, 
        'CurrentResolutionUnits': App.Constants.ResolutionUnits.PixelsPerIn, 
        'Height': height, 
        'MaintainAspectRatio': True, 
        'Resample': True, 
        'ResampleType': App.Constants.ResampleType.Bicubic, 
        'ResizeAllLayers': True, 
        'Resolution': 300, 
        'Width': width, 
        'SharpnessValue': 50, 
        'AdvancedMode': True, 
        'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match, 
                'Version': ((12,0,1),1)
        }
        })
JoeB
Posts: 2662
Joined: Fri Mar 28, 2008 10:04 pm
operating_system: Windows 8.1
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: LENOVO 4524PE4 ThinkCentre M91p
processor: 3.10 gigahertz Intel Quad Core i5-2400
ram: 8 GB
Hard_Drive_Capacity: 4.6 TB
Corel programs: PSP 9, X7 to 2019, 32 & 64-bit
Location: Canada

Re: Resize depending on landscape or portrait mode?

Post by JoeB »

And I would ask that you please complete your forum Profile to add the version of PSP that you're using. This will prevent people reading any other posts from you from providing answers that perhaps might not apply to the version of PSP that you are using.
Regards,

JoeB
Using PSP 2019 64bit
User avatar
Tony Lenton
Posts: 31
Joined: Wed Jan 18, 2006 8:28 am
operating_system: Windows 7 Professional
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Intel DH55TC
processor: Intel Core i5 3.20 GHz
ram: 12GB
Video Card: GeForce GTX 1060
sound_card: On board Realtek High Def Audio
Hard_Drive_Capacity: 4500 GB
Monitor/Display Make & Model: Lenovo S27i
Corel programs: PSP X6 PSP2020
Location: Frenaros, Cyprus

Re: Resize depending on landscape or portrait mode?

Post by Tony Lenton »

I've just come across this thread after searching for "Resize" as the script I was using was causing me some problems.

I didn't realise that there was a built in Resize option in the Batch Processing and this works well for what I want. Is there any way to get rid of the Artistic.jpg sample that shows up every time you start the process? I've deleted all the occurrences that I've found but it still shows up and recreates itself after PSP shuts down.
Jean-Luc
Posts: 1676
Joined: Sat Oct 22, 2011 10:50 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: ASUS Computer N751J
processor: Intel i7-4710 HQ 2.50GHz
ram: 16GB
Video Card: NVIDIA GeForce GTX 850M
sound_card: NVIDIA High Definition Audio
Hard_Drive_Capacity: 2 Tb
Monitor/Display Make & Model: NVIDIA GeForce GTX 850M
Corel programs: PSP X7, X8, X9, 2018, 2019, 2020, 2021
Location: Belgium (French speaking)
Contact:

Re: Resize depending on landscape or portrait mode?

Post by Jean-Luc »

Tony Lenton wrote: Is there any way to get rid of the Artistic.jpg sample that shows up every time you start the process?
Go to Manage workspace.
Under Navigation / Computer select an empty folder or "your PC" (and not a folder) and/or be sure no image is selected in a Tray.
THE PAINTSHOP PRO COOKBOOK
Installed PSP Ultimate: X7, X8, X9, 2018, 2019, 2020 and 2021.
User avatar
Tony Lenton
Posts: 31
Joined: Wed Jan 18, 2006 8:28 am
operating_system: Windows 7 Professional
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Intel DH55TC
processor: Intel Core i5 3.20 GHz
ram: 12GB
Video Card: GeForce GTX 1060
sound_card: On board Realtek High Def Audio
Hard_Drive_Capacity: 4500 GB
Monitor/Display Make & Model: Lenovo S27i
Corel programs: PSP X6 PSP2020
Location: Frenaros, Cyprus

Re: Resize depending on landscape or portrait mode?

Post by Tony Lenton »

Jean-Luc wrote: Go to Manage workspace.
Under Navigation / Computer select an empty folder or "your PC" (and not a folder) and/or be sure no image is selected in a Tray.
Hi

Thanks for that. It took me a few minutes because I only ever have the Edit tab visible and I was looking for a menu item with "Manage Workspace" :oops:
I experimented by renaming Artistic.jpg and the Batch comand always seems to pick the first file in the Samples folder.

Thanks again.
Jean-Luc
Posts: 1676
Joined: Sat Oct 22, 2011 10:50 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: ASUS Computer N751J
processor: Intel i7-4710 HQ 2.50GHz
ram: 16GB
Video Card: NVIDIA GeForce GTX 850M
sound_card: NVIDIA High Definition Audio
Hard_Drive_Capacity: 2 Tb
Monitor/Display Make & Model: NVIDIA GeForce GTX 850M
Corel programs: PSP X7, X8, X9, 2018, 2019, 2020, 2021
Location: Belgium (French speaking)
Contact:

Re: Resize depending on landscape or portrait mode?

Post by Jean-Luc »

Tony Lenton wrote: Ithe Batch comand always seems to pick the first file in the Samples folder.
Manage Workspace empty.jpg
THE PAINTSHOP PRO COOKBOOK
Installed PSP Ultimate: X7, X8, X9, 2018, 2019, 2020 and 2021.
Post Reply