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()
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%
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()
