PaintShop Pro Gradient Reader and Writer

Moderator: Kathy_9

Post Reply
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

PaintShop Pro Gradient Reader and Writer

Post by LeviFiction »

This is a useless script.

It provides two classes, Gradient_Writer an Gradient_Reader. These classes allow you to read in a PSPGradient file and write one out. Why would you ever want to do this? That's anyone's guess.

Some examples where these might come in handy:

Gradient_Reader could be used in say an SVG Export script - in order to export the gradient information for vectors you need to be able to read the color stops and transparency stops from the gradient files as PSP does not return these programmatically all of the time.

Gradient_Writer could be used to import gradients from other formats into PSP Gradients.

Will anyone use these? Probably not.

Quick how-to:

Gradient_Reader - Really only has one function. getMaterial() it returns the dictionary parameter for the gradient. You can then use this to create swatches, assign it to the active tool.....pretty much everything you could do if you just told PSP to use the gradient by name directly instead of reading it in.

Code: Select all

grd = Gradient_Reader(path_to_gradient)
Material = grd.getMaterial()
Gradient_Writer - You add each color spot and each transparency spot, then you call write to save out the result.

addColorStop( [Red,Green,Blue], Location, midpoint, type, LocPerc) - [Red, Green, Blue] is a list of three values each between 0-255. Location is either a percentage (0-100) or a explicit value between 0 and 4096. Whether you're using Percentage or not is determiend by LocPerc (LocationPercentage). If you want Location to be a percentage set LocPerc to True. Midpoint is a percentage 0-100 only. Midpoint defaults to 50. LocPerc defaults to False. Type is either 0 - Custom color 1- Foreground or 2- Background.

The following are all valid calls to AddColorStop()

Code: Select all

grd.addColorStop( [255,0,0], 0)  #Sets a red color stop at position 0
grd.addColorStop( [255,255,0], 100, LocPerc= True)  #Sets a yellow color stop at position 100%
grd.addColorStop( [255,255,255], 50, 75, LocPerc = True) #Sets a white color stop at location 50% with a midpoint at 75%  
grd.addColorStop( [0,0,0], 25, LocPerc = True, type = 1) #Sets a color stop using the Foreground color at location 25%
addTrasnparencyStop(Opacity, Location, Midpiont, LocPerc) - Opacity is a percentae between 0 and 100. Location is either an absolute value between 0 and 4096 or a percentage 0-100. If you set LocPerc = True then it'll use percentage for the location. If you don't define it it defaults to false and Location becomes and absolute value. Midpoint is a percentage between 0 and 100. Defaults to 50

The following are valid calls to addTransparencyStop()

Code: Select all

grd.addTransparencyStop(100, 0)  #Sets a transparency stop point at 0 with an opacity of 100%
grd.addTransparencyStop(100, 100, LocPerc=True) #Sets a transparency stop point at 100% (4096) with an opacity of 100%.  Using Percents for the location as determiend by LocPerc.
grd.addTransparencyStop(25, 50, 75, LocPerc=True) #Sets a transparency stop of 25% opacity at 50% location, 75% 

Code: Select all

path_to_new_file = 'C:\Users\Levi\Desktop\Gradient1.pspgradient'
grd = Gradient_Writer(path_to_new_file, 'Gradient Name')
grd.addColorStop( [255,0,0], 0)
grd.addColorStop([0,0,255], 100, LocPerc = True)
grd.addTransparencyStop(100,0)
grd.addTransaprencyStop(100,100, LocPerc=true)
grd.write()
https://drive.google.com/file/d/0B8FlFL ... sp=sharing
Last edited by LeviFiction on Wed Jun 29, 2016 6:27 am, edited 1 time in total.
https://levifiction.wordpress.com/
JoeB
Posts: 2778
Joined: Fri Mar 28, 2008 10:04 pm
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
Location: Canada

Re: PaintShop Pro Gradient Reader and Writer

Post by JoeB »

Glad to see you're having fun with scripting and keeping your hand in with continuing practice! Whether or not that practice turns out to have generated a practical use only time and other users will tell! :-)
Regards,

JoeB
Using PSP 2019 64bit
Post Reply