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?
Run Resize silent & maintain heigh aspect with fixed width?
Moderator: Kathy_9
-
JoeB
- Posts: 2778
- Joined: Fri Mar 28, 2008 10:04 pm
- 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
Run Resize silent & maintain heigh aspect with fixed width?
Regards,
JoeB
Using PSP 2019 64bit
JoeB
Using PSP 2019 64bit
-
LeviFiction
- Advisor
- Posts: 6831
- Joined: Thu Oct 02, 2008 1:07 pm
- 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: Run Resize silent & maintain heigh aspect with fixed wid
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.
Just pass in newHeight an you'll be good.
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
https://levifiction.wordpress.com/
-
JoeB
- Posts: 2778
- Joined: Fri Mar 28, 2008 10:04 pm
- 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: Run Resize silent & maintain heigh aspect with fixed wid
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
Using PSP 2019 64bit
