script for autocropping

Moderator: Kathy_9

Post Reply
terryl
Posts: 3
Joined: Wed Dec 26, 2012 7:02 pm
operating_system: Windows 7 Home Premium
System_Drive: C
32bit or 64bit: 32 Bit

script for autocropping

Post by terryl »

New to X5 version of PSP although long term user of very old versions.
I am trying to write a script to crop a large number of pages (images) into to 2 parts. Now I can record a script that works for the one image I am using at the time, but it will not run once I try a small batch.
This is my script that I recorded for giving me the left hand side of the image, I need to do the same for the right hand side and save separately, I have nearly 500 images to split into 2:-

from PSPApp import *

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

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

# FileOpen
App.Do( Environment, 'FileOpen', {
'FileList': [u'E:\\*************************************\\New folder\\N'\
u'ew folder\\New folder\\IMG_4660.JPG'],
'Folder': u'E:\\************************************\New folder\\New '\
u'folder\\New folder',
'FileFormat': App.Constants.FileFormat.Unknown,
'ShowPreview': True,
'EnableBrowser': True,
'FavFileList': [],
'RawCameraSettings': {
'WhiteBalance': App.Constants.WhiteBalance.AsShot,
'SharpenMode': App.Constants.SharpenMode.Low,
'Exposure': 0,
'Rect': ((0,0), 0, 0),
'ShowMaximized': False,
'ShowPreview': True
},
'FileOpenScript': u'',
'EnablePreprocessing': False,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((15,0,0),1)

Any help please????
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 for autocropping

Post by LeviFiction »

Umm....well that script is incomplete for what it sounds like you're trying to do.

That script only shows opening an image. And if you're running a batch script the FileOpen section is actually unnecessary since PSP will be doing all of the opening.

Did the script record anything more? Or was this it?
https://levifiction.wordpress.com/
terryl
Posts: 3
Joined: Wed Dec 26, 2012 7:02 pm
operating_system: Windows 7 Home Premium
System_Drive: C
32bit or 64bit: 32 Bit

Re: script for autocropping

Post by terryl »

No that was it, nothing else recorded- I went through the whole procedure with record on then I saved the script as I thought.
So it was:-

Open image
select crop
selected section to crop to
cropped
saved cropped image to a separate folder
then close image
then closed original image without saving changes.
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 for autocropping

Post by LeviFiction »

Hmmm...that's odd.

Well you could try recording the script again, this time record it without opening the file since that's not necessary? See if it will record any further this time.

Otherwise, answer a few questions and I might be able to make one from scratch for you.

1) Is the Crop directly in half? So the first image is 50% the width and the second image is 61%-100% of the image?

2) If not directly in half, what are the dimensions of the Image and the crop?

3) Are all of the images exactly the same size?
https://levifiction.wordpress.com/
terryl
Posts: 3
Joined: Wed Dec 26, 2012 7:02 pm
operating_system: Windows 7 Home Premium
System_Drive: C
32bit or 64bit: 32 Bit

Re: script for autocropping

Post by terryl »

After a lot of playing around I have now got it to work EXCEPT I'm left with the same number of windows open as the number of files I have processed , which means I have to shut down the programme before I can do anything else.
I've now got the script for both halves and get the same size final images

This is my script now for the left hand crop:-
from PSPApp import *

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

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

# Crop
App.Do( Environment, 'Crop', {
'CropRect': ((8,0), 1995, 3188),
'Mode': App.Constants.CropMode.Custom,
'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': ((15,0,0),1)
}
})

# CropFixup
App.Do( Environment, 'CropFixup', {
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Silent,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((15,0,0),1)
}
})

# FileSaveAs
App.Do( Environment, 'FileSaveAs', {
'Encoding': {
'JPG': {
'Variant': App.Constants.JpegFormat.Standard,
'CompressionFactor': 20,
'ChromaSubSampling': App.Constants.ChromaSubSampling.YCC_1x1_1x1_1x1,
'EXIF': True,
'EmbedJPGICC': True
}
},
'FileName': u'C:\\Users\\Terry\\Desktop\\left side\\IMG_4652.jpg',
'FileFormat': App.Constants.FileFormat.JPG,
'FormatDesc': u'JPG JPEG ',
'WorkingMode': 0,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.AllAlways,
'Version': ((15,0,0),1)
},
'DefaultProperties': []
})

# FileClose
App.Do( Environment, 'FileClose', {
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Silent,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((15,0,0),1)
}
})

# SelectDocument
App.Do( Environment, 'SelectDocument', {
'SelectedImage': -1,
'Strict': False,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((15,0,0),1)
}
})
Post Reply