Script to resize-convert WMF

Moderator: Kathy_9

Post Reply
nanrector
Posts: 65
Joined: Wed Aug 08, 2012 12:58 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
processor: Intel Core i7-8700 CPU 3.2GHz 6 Core
ram: 32 GB
Video Card: NVIDIA GeForce GTX 1070
Hard_Drive_Capacity: 10 TB
Corel programs: PSP 2019 Ultimate
Location: Arizona
Contact:

Script to resize-convert WMF

Post by nanrector »

Hello!

I have a bunch of WMF files I'm trying to open at a large size and then concert to PNG with a recorded script batch but I'm not quite sure how to get a script to do the entire sequence. When I open each graphic it brings up the Meta Picture Import screen. I need them to be re-sized to about 2000 pixels wide. (They can all be this size for ease of import.) I then need them all saved as PNGs.

I can record a script to to save them but I'm unsure how to get it to open and re-size first them THEN do the save so I can run it as a batch on the folder. Can I script the entire process?

Thanks so much!
Nancy
PSP X on Windows 7
Nancy Ü

PSP X4
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 to resize-convert WMF

Post by LeviFiction »

EDIT: Let me start over.

1) Most of that is scriptable -yes. You can even make a script process an entire folder for you. The only part that isn't scriptable is the import size. PSP will always ask you for the import size when you open up a WMF file even if you tell it to do this "silently"


2) The best way to proceed is to use the Batch Processing command. The Batch Processing command will not ask you for the size. And saving to PNG couldn't be easier. The only thing you need is a script that runs the "resize" command and set the size you want.
To do this, open any file.

Hit record on the script toolbar.

Run the "Resize" command with a Width of "2000" (or height if you prefer).

Save the script.

Edit the script in notepad. Delete the side that you don't want to use (Width or Height). This will make sure it always attempts to resize to that width or height only.
Then in the Batch Processor you pick the files that you want in the batch.

You select "New Type" as the save mode. You tell it to save as a PNG. You can give it a folder to save the new file in if you want.

Check the checkbox that says "Use Script" and "Silent Mode" then select your resize script.

When you hit the "Start" button it'll open, process, and save all of the files in quick succession. With minimal effort on your part.
https://levifiction.wordpress.com/
nanrector
Posts: 65
Joined: Wed Aug 08, 2012 12:58 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
processor: Intel Core i7-8700 CPU 3.2GHz 6 Core
ram: 32 GB
Video Card: NVIDIA GeForce GTX 1070
Hard_Drive_Capacity: 10 TB
Corel programs: PSP 2019 Ultimate
Location: Arizona
Contact:

Re: Script to resize-convert WMF

Post by nanrector »

That's wonderful! I just didn't know enough on how to set it up. I tested it and its working however its not keeping the ratio. I deleted the "height" line from the script and kept the width. Am I missing something? Below is my script:





from PSPApp import *

def ScriptProperties():
return {
'Author': u'',
'Copyright': u'',
'Description': u'',
'Host': u'Paint Shop Pro X',
'Host Version': u'10.00'
}

def Do(Environment):
# EnableOptimizedScriptUndo
App.Do( Environment, 'EnableOptimizedScriptUndo', {
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((10,0,1),1)
}
})

# Resize
App.Do( Environment, 'Resize', {
'AspectRatio': 1,
'CurrentDimensionUnits': App.Constants.UnitsOfMeasure.Pixels,
'CurrentResolutionUnits': App.Constants.ResolutionUnits.PixelsPerIn,
'MaintainAspectRatio': True,
'Resample': True,
'ResampleType': App.Constants.ResampleType.SmartSize,
'ResizeAllLayers': True,
'Resolution': 300,
'Width': 2000,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((10,0,1),1)
}
})
Nancy Ü

PSP X4
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 to resize-convert WMF

Post by LeviFiction »

Yeah, no that's my fault. I keep forgetting the Resize command doesn't like to recalculate all on its own unless the dialog pops up. But that's easy to fix.

We just have to do the math ourselves.

AspectRatio = ImageWidth /Image Height
If Width = 2000 then Height = 2000/AspectRatio
If Height = 2000 then Width = 2000 * AspectRatio.

In this case we have width being the constant so we'll use the first one.

You'll notice I add 3 lines and then set the variables directly into the command in 3 locations: AspectRatio, Width, and Height. You can see just how simple it is to do.

Code: Select all

from PSPApp import *

def ScriptProperties():
    return {
        'Author': u'',
        'Copyright': u'',
        'Description': u'',
        'Host': u'PaintShop Pro',
        'Host Version': u'10.00'
        }


def Do(Environment):
    # EnableOptimizedScriptUndo
    App.Do( Environment, 'EnableOptimizedScriptUndo', {
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match, 
                'Version': ((10,0,0),1)
                }
            })

    # Calculate new sizes
    # Then Resize
    
    AspectRatio = (App.ActiveDocument.Width * 1.0) / App.ActiveDocument.Height
    newwidth = 2000.0
    newheight = newwidth / AspectRatio
    
    App.Do( Environment, 'Resize', {
            'AspectRatio': AspectRatio, 
            'CurrentDimensionUnits': App.Constants.UnitsOfMeasure.Pixels, 
            'CurrentResolutionUnits': App.Constants.ResolutionUnits.PixelsPerIn, 
            'Height': newheight, 
            'MaintainAspectRatio': True, 
            'Resample': True, 
            'ResampleType': App.Constants.ResampleType.SmartSize, 
            'ResizeAllLayers': True, 
            'Resolution': 300, 
            'Width': newwidth, 
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match, 
                'Version': ((10,0,0),1)
                }
            }) 
And in case you're curious about the whole (App.ActiveDocument.Wdith * 1.0) that's just because Python won't produce decimals unless you divide with a number with decimals.
Attachments
ResizeWidth2000.zip
(655 Bytes) Downloaded 265 times
https://levifiction.wordpress.com/
nanrector
Posts: 65
Joined: Wed Aug 08, 2012 12:58 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
processor: Intel Core i7-8700 CPU 3.2GHz 6 Core
ram: 32 GB
Video Card: NVIDIA GeForce GTX 1070
Hard_Drive_Capacity: 10 TB
Corel programs: PSP 2019 Ultimate
Location: Arizona
Contact:

Re: Script to resize-convert WMF

Post by nanrector »

Thank you SO much Levi for taking the time to do that more me. This will save me a ton of time. I will also save your instructions for further reference.

Have a wonderful day!
Nancy

LeviFiction wrote:Yeah, no that's my fault. I keep forgetting the Resize command doesn't like to recalculate all on its own unless the dialog pops up. But that's easy to fix.

We just have to do the math ourselves.

AspectRatio = ImageWidth /Image Height
If Width = 2000 then Height = 2000/AspectRatio
If Height = 2000 then Width = 2000 * AspectRatio.

In this case we have width being the constant so we'll use the first one.

You'll notice I add 3 lines and then set the variables directly into the command in 3 locations: AspectRatio, Width, and Height. You can see just how simple it is to do.

Code: Select all

from PSPApp import *

def ScriptProperties():
    return {
        'Author': u'',
        'Copyright': u'',
        'Description': u'',
        'Host': u'PaintShop Pro',
        'Host Version': u'10.00'
        }


def Do(Environment):
    # EnableOptimizedScriptUndo
    App.Do( Environment, 'EnableOptimizedScriptUndo', {
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match, 
                'Version': ((10,0,0),1)
                }
            })

    # Calculate new sizes
    # Then Resize
    
    AspectRatio = (App.ActiveDocument.Width * 1.0) / App.ActiveDocument.Height
    newwidth = 2000.0
    newheight = newwidth / AspectRatio
    
    App.Do( Environment, 'Resize', {
            'AspectRatio': AspectRatio, 
            'CurrentDimensionUnits': App.Constants.UnitsOfMeasure.Pixels, 
            'CurrentResolutionUnits': App.Constants.ResolutionUnits.PixelsPerIn, 
            'Height': newheight, 
            'MaintainAspectRatio': True, 
            'Resample': True, 
            'ResampleType': App.Constants.ResampleType.SmartSize, 
            'ResizeAllLayers': True, 
            'Resolution': 300, 
            'Width': newwidth, 
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match, 
                'Version': ((10,0,0),1)
                }
            }) 
And in case you're curious about the whole (App.ActiveDocument.Wdith * 1.0) that's just because Python won't produce decimals unless you divide with a number with decimals.
Nancy Ü

PSP X4
Post Reply