Basically, I have a bunch of different landscape images, with different dimensions. I want to crop the center part of each image and that center part must have a 16 x 9 ratio. So, the full width of the image and then the height sticking to the correct ratio. And the cropped part is in the center of the image, in other words, an equal part is cropped off the top and bottom.
PSP (2018) has this functionality built in. Just go to the crop tool and select the preset 16 x 9. You get a crop selection, with the correct ratio, full width (whatever the width of the image may be) and centered. So far so good.
But recording this and turning it into a script, does not work.
The built in preset looks like this:
Code: Select all
from PSPApp import *
def ScriptProperties():
return {
'Author': u'',
'Copyright': u'',
'Description': u'',
'Host': u'Corel PaintShop Pro',
'Host Version': u'15.00'
}
def Preset_Crop():
return {
'CropRect': ((0,0), 1600, 900),
'Mode': App.Constants.CropMode.CustomAR,
'Units': App.Constants.CropUnits.Inches,
'SelectedArea': False,
'PrintWidth': -1,
'PrintHeight': -1,
'CropAsNewImage': True,
'RotationAngle': 0,
'AutoFit': True
}
def Do(Environment):
# Crop_LOCALIZED
App.Do( Environment, 'Crop', Preset_Crop())Below is a recorded example:
Code: Select all
from PSPApp import *
def ScriptProperties():
return {
'Author': u'',
'Copyright': u'',
'Description': u'',
'Host': u'PaintShop Pro',
'Host Version': u'20.00'
}
def Do(Environment):
# EnableOptimizedScriptUndo
App.Do( Environment, 'EnableOptimizedScriptUndo', {
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((20,0,0),1)
}
})
# Crop
App.Do( Environment, 'Crop', {
'CropRect': ((0,1151.41), 11387, 6405.19),
'Mode': App.Constants.CropMode.CustomAR,
'Units': App.Constants.CropUnits.Inches,
'SelectedArea': False,
'PrintWidth': -1,
'PrintHeight': -1,
'CropAsNewImage': False,
'RotationAngle': 0,
'AutoFit': False,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((20,0,0),1)
}
})So, what does the built in tool do extra to get the right result each time? How does it go from the original text and 'CropRect': ((0,0), 1600, 900), to the proper location and size?
