NEW! PaintShop Pro 2019

Run Resize silent & maintain heigh aspect with fixed width?

Moderator: Kathy_9

Run Resize silent & maintain heigh aspect with fixed width?

Postby JoeB » Sat Feb 09, 2019 8:48 pm

I was experimenting with a script to automate a procedure that @Bareboats asked about in the main forum here:

viewtopic.php?f=56&t=64994

In doing so I ran into what appears to be an issue. Normally, when I open the Resize dialogue with a recorded script with the Pixel Size tab selected, and the script has a fixed width of 520 pixels and Maintain Aspect Ratio checked, and the script is run interactively to show the dialogue, then whatever image I run that script on will result in the width shown as 520 and the height adjusted accordingly to maintain the correct aspect ratio for any particular image that might have a different aspect ratio. However, if I run the script silently then, while it maintains the 520 pixel width, it also reads the previous setting for height that is also recorded in the script instead of allowing the height to adjust automatically. This is despite the fact that Maintain Aspect Ration is set to True in the script. And, as I said, when run interactively so that the dialogue actually shows up then the aspect ratio is maintained with any size image even though the previous height from the previous image with which I recorded the script is in the script.

Is there a reason for this? If so, can something be done to allow the script to run the resize dialogue silently and maintain the width I always want while automatically changing the height to maintain the aspect ratio when run on images of different sizes and aspect ratios?
Regards,

JoeB
Using PSP 2019 64bit
JoeB
 
Posts: 2315
Joined: Fri Mar 28, 2008 10:04 pm
Location: Canada
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

Re: Run Resize silent & maintain heigh aspect with fixed wid

Postby LeviFiction » Sat Feb 09, 2019 10:11 pm

This is standard operation procedure for all commands. If a parameter is left blank it'll use the last used value in that spot. All of the logic for ensuring the aspect ratio is maintained is inside the dialog box itself. The command called just uses whatever it's given as input. So when you run silently, it never runs the code to update the aspect ratio.

You see the same thing in other commands like SaveAs. If you run that silently it won't care what file extension you use it'll use any valid Windows filename you hand it assuming you know what you're doing. If it's run interactively, the dialog will force the appropriate extension for the file type chosen.

To maintain the aspect ratio, you have two options. 1) Do the math yourself and pass in the new height or 2) use the Resize By Side mode. This will limit your script to only those versions of PSP that support that mode but it works without needing extra code.

Code: Select all
    ar = App.TargetDocument.Width / (App.TargetDocument.Height * 1.0)  #Multiplying by 1.0 to convert it to a float for accurate division,  float(App.TargetDocument.Height) would also work.
    newHeight = int(round(newWidth / ar)) #round the result then convert to integer


Just pass in newHeight an you'll be good.
LeviFiction
Advisor
 
Posts: 5349
Joined: Thu Oct 02, 2008 1:07 pm
Location: USA
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
Corel programs: PSP: 8, 9, X, XI, X2, X8,X9, 2018, 2019

Re: Run Resize silent & maintain heigh aspect with fixed wid

Postby JoeB » Sat Feb 09, 2019 11:29 pm

Thanks so much Levi! Will be testing both suggestions out shortly. The code is likely best in case others with older versions of PSP need to use the Resize command in a script to maintain aspect ratio.
Regards,

JoeB
Using PSP 2019 64bit
JoeB
 
Posts: 2315
Joined: Fri Mar 28, 2008 10:04 pm
Location: Canada
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


Return to PSP Scripting

Who is online

Users browsing this forum: No registered users and 1 guest