Here is a complete list of Functions and Classes that are currently available in Draft, as well as a short description on their use and parameters. A short sample code snippet is also posted for each function. If you have any questions regarding any of this functionality, feel free to ask
–Utilities–
These are just basic objects and enums that are used as parameters throughout Draft’s other functions.
CompositeOperator
Description: This enum contains all the operators available when compositing images.
Values:
[list] UndefinedCompositeOp
OverCompositeOp
InCompositeOp
OutCompositeOp
AtopCompositeOp
XorCompositeOp
PlusCompositeOp
MinusCompositeOp
AddCompositeOp
SubtractCompositeOp
DifferenceCompositeOp
MultiplyCompositeOp
BumpmapCompositeOp
CopyCompositeOp
CopyRedCompositeOp
CopyGreenCompositeOp
CopyBlueCompositeOp
CopyOpacityCompositeOp
Sample Code:
compOperator = Draft.CompositeOperator.OverCompositeOp
Anchor
Type: Enum
Description: This enum contains the different values that can be provided to functions that require positional anchor Arguments.
Values:
NorthWest
North
NorthEast
West
Center
East
SouthWest
South
SouthEast
Sample Code:
anchor = Draft.Anchor.NorthWest
PositionalGravity
Type: Enum
Description: Deprecated. Please see Anchor instead. This enum contains the different values that can be provided to functions that require positional Arguments.
Values:
NorthWestGravity
NorthGravity
NorthEastGravity
WestGravity
CenterGravity
EastGravity
SouthWestGravity
SouthGravity
SouthEastGravity
Sample Code:
gravity = Draft.PositionalGravity.NorthWestGravity
ColorRGBA
Type: Class
Description: This class represents a color, in RGBA format.
Properties:
R – A decimal value representing the red component (0.0-1.0)
G – A decimal value representing the green component (0.0-1.0)
B – A decimal value representing the blue component (0.0-1.0)
A – A decimal value representing the alpha component (0.0-1.0)
Sample Code:
newColor = Draft.ColorRGBA( 0.75, 0.54, 0.975, 1.0 )
- or -
newColor = Draft.ColorRGBA()
newColor.R = 0.75
newColor.G = 0.54
newColor.B = 0.975
newColor.A = 1.0
AnnotationInfo
Type: Class
Description: A class that contains properties used for textual annotations
Properties:
PointSize – An integer value denoting the size of the font. (defaults to 32)
FontType – A string value denoting the type of font to use. (defaults to Adobe’s Source Sans Pro)
FontMetric – A FontTypeMetric object used to retrieve font and text properties for the annotation. Its values are set when the annotation is created.
Padding – A decimal value denoting the padding around the text. (defaults to 0.0)
Color – A Draft.ColorRGBA value denoting the color of the text. (defaults to white)
BackgroundColor – A Draft.ColorRGBA value denoting the background color. (defaults to transparent)
DrawShadow – A boolean value denoting whether or not to draw a shadow around the text. (defaults to false)
ShadowColor – A Draft.ColorRGBA value denoting the color of the Shadow. (defaults to black)
Sample Code:
textInfo = Draft.AnnotationInfo()
textInfo.PointSize = 24
textInfo.FontType = "Helvetica"
textInfo.Color = Draft.ColorRGBA( 0.75, 0.54, 0.975, 1.0 )
textInfo.BackgroundColor = Draft.ColorRGBA( 0.0, 0.0, 0.0, 0.0 )
FontTypeMetric
Type: Class
Description: A class to retrieve font and text properties for annotations.
Properties:
Ascent – The distance in pixels from the text baseline to the highest/upper grid coordinate used to place an outline point.
Descent – The distance in pixels from the baseline to the lowest grid coordinate used to place an outline point. Always a negative value.
TextHeight – The height in pixels of the text written, this does not include any padding
TextWidth – The width in pixels of the text written, this does not include any padding
BaselineOffset – Offset in pixels from the bottom of the image to the baseline used to write the text. Use this to align text from different point sizes and fonts.
MaxHorizontalAdvance – Maximum horizontal advance in pixels.
[/list:u]
Draft.Image
The Draft.Image class contains all of Draft’s image-related functionality. It contains two types of functions: Static functions, and Member functions. Static functions can be invoked without an instance (by calling Draft.Image.), whereas Member functions require to be invoked from an instance of a Draft.Image object (by calling .).
The Static functions are used to create new instances of the Draft.Image class, whereas the Member functions are used to modify pre-existing instances of the Draft.Image. The sample code snippets should clarify this distinction function in case you are unsure.
Draft.Image Properties
width – An integer value indicating the width of the image.
height – An integer value indicating the height of the image.
Draft.Image Static Functions:
CreateImage
Type: Static
Description: Returns a new image of the specified size with RGBA channels.
Arguments:
[list]Width – An integer value denoting the width of the image to create
Height – An integer value denoting the height of the image to create
Usage:
newImage = Draft.Image.CreateImage( 800, 600 )
[b]ReadFromFile[/b]
[i]Type[/i]: Static
[i]Description[/i]: Returns a new image from a file on disk, (supports various image types determined by file extension).
[i]Arguments[/i]:
Filename -- A string value indicating where on the machine to find the image file.
[i]Usage[/i]:
[code]
imageFromFile = Draft.Image.ReadFromFile( “//path/to/image/file.png” )
[/code]
[b]CreateAnnotation[/b]
[i]Type[/i]: Static
[i]Description[/i]: Returns a new image consisting of the specified text. The provided AnnotationInfo object describes the various text parameters.
[i]Arguments[/i]:
Text -- A string value providing the contents of the annotation.
TextInfo -- A Draft.AnnotationInfo value providing parameters describing how to draw the text.
[i]Usage[/i]:
textInfo = Draft.AnnotationInfo()
textImage = Draft.Image.CreateAnnotation( "This is the text that will be in the image", textInfo )
[b]Anaglyph[/b]
[i]Type[/i]: Static
[i]Description[/i]: Returns an anaglyph of the speficied type created from the two left/right input images.
[i]Arguments[/i]:
LeftImage -- A Draft.Image containing the left-eye image.
RightImage -- A Draft.Image containing the right-eye image.
AnaglyphType -- A string value containing the anaglyph type; can be either "LSA" or "PS".
[i]Usage[/i]:
[code]
anaglyphImage = Draft.Image.Anaglyph( leftEye, rightEye, “LSA” )
[/code]
[/list:u]Draft.Image Member Functions
WriteToFile
Type: Member
Description: Writes the image to a file on disk, (supports various image types determined by file extension).
Arguments:
[list]Filename – A string value indicating where to save the file to.
Usage:
someImage = Draft.Image.CreateImage( 800, 600 )
someImage.WriteToFile( "//path/to/save/location.png" )
[b]Crop[/b]
[i]Type[/i]: Member
[i]Description[/i]: Crops the image to the given bounds.
[i]Arguments[/i]:
Left -- An integer value denoting the left bound of the crop
Bottom -- An integer value denoting the bottom bound of the crop
Right -- An integer value denoting the right bound of the crop
Top -- An integer value denoting the top bound of the crop
[i]Usage[/i]:
someImage = Draft.Image.CreateImage( 800, 600 )
someImage.Crop( 100, 150, 200, 250 )
[b]Resize[/b]
[i]Type[/i]: Member
[i]Description[/i]: Resizes the image to the given size.
[i]Arguments[/i]:
width -- An integer value denoting the width to which the image will be re-sized.
height -- An integer value denoting the height to which the image will be re-sized.
type -- Optional. A string that specifies how the image data should be scaled to fit the new size. Default is 'fit'. Valid type values are:
[list]* 'none' -- don't scale the image data
[*]'width' -- scale the image to fit the new width, without changing the aspect ratio
[*]'height' -- scale the image to fit the new height, without changing the aspect ratio
-
‘fit’ – scale the image as large as possible while staying inside the new image, without changing the aspect ratio
-
‘fill’ – scale the image as small as possible while covering the new image, without changing the aspect ratio
-
‘distort’ – scale the image to match the new width and height, changing the aspect ratio if necessary
border -- Optional. A string that specifies how the border around a resized image should be set. Default is 'transparent'. Border argument doesn't do anything if the type is 'fill'. Valid border values are:
* 'transparent' -- set the border to be transparent
-
‘stretch’ – stretch the left, right, top and bottom edges of the image to the edge of the resized frame
[/*:m][/list:u]
Usage:
someImage = Draft.Image.CreateImage( 800, 600 )
someImage.Resize( 1920, 1080 )
- or -
someImage = Draft.Image.CreateImage( 800, 600 )
someImage.Resize( 1920, 1080, 'distort' )
- or -
someImage = Draft.Image.CreateImage( 800, 600 )
someImage.Resize( 1920, 1080, 'fit', 'stretch' )
[b]SetChannel[/b]
[i]Type[/i]: Member
[i]Description[/i]: Set an image channel to the specified value.
[i]Arguments[/i]:
channel -- the channel to set. Typical channels are 'R', 'G', 'B', and 'A'.
value -- the value to assign to the channel. Typically in the range from 0.0 to 1.0.
[i]Usage[/i]:
[code]someImage = Draft.Image.ReadFromFile( "//path/to/some/image/file.png" )
someImage.SetChannel( ‘A’, 1.0 )[/code]
[b]SetToColor[/b]
[i]Type[/i]: Member
[i]Description[/i]: Sets the image to the given color.
[i]Arguments[/i]:
Color -- A Draft.ColorRGBA value indicating the color that the image should be set to
[i]Usage[/i]:
[code]someImage = Draft.Image.CreateImage( 800, 600 )
someImage.SetToColor( Draft.ColorRGBA( 1.0, 0.0, 0.0, 1.0 ) )[/code]
[b]ApplyGamma[/b]
[i]Type[/i]: Member
[i]Description[/i]: Apply a gamma correction to the image.
[i]Arguments[/i]:
Gamma -- A float value indicating the gamma that should be applied
[i]Usage[/i]:
[code]someImage = Draft.Image.ReadFromFile( "//path/to/some/image/file.png" )
someImage.ApplyGamma( 2.2 )[/code]
[b]Composite[/b]
[i]Type[/i]: Member
[i]Description[/i]: Composites an image with the current image at the given location using the specified compositing operation.
[i]Arguments[/i]:
Image -- A Draft.Image that will be composited with the image on which this function was invoked.
Left -- A float value that denotes how far from the left the composite operation should take place.
Bottom -- A float value that denotes how far from the bottom the composite operation should take place.
Operation -- A Draft.CompositeOperator enum value indicating the type of operation to perform
Usage:
[code]someImage = Draft.Image.CreateImage( 800, 600 )
someOtherImage = Draft.Image.ReadFromFile( “//path/to/some/image/file.png” )
someImage.Composite( someOtherImage, 0, 0.33, Draft.CompositeOperator.OverCompositeOp )[/code]
[b]CompositeWithAnchor[/b]
[i]Type[/i]: Member
[i]Description[/i]: Composites an image with the current image using the specified positional anchor to determine the location of the image being composited.
[i]Arguments[/i]:
Image -- A Draft.Image that will be composited with the image on which this function was invoked.
Anchor -- A Draft.Anchor enum value used to determine the location on the current image where Image will be composited.
Operation -- A Draft.CompositeOperator enum value indicating operation to perform
[i]Usage[/i]:
[code]someImage = Draft.Image.CreateImage( 800, 600 )
someOtherImage = Draft.Image.ReadFromFile( “//path/to/some/image/file.png” )
someImage.CompositeWithAnchor( someOtherImage, Draft.Anchor.NorthWest, Draft.CompositeOperator.OverCompositeOp )[/code]
[b]CompositeWithGravity[/b]
[i]Type[/i]: Member
[i]Description[/i]: Deprecated. Please see CompositeWithAnchor instead. Composites an image with the current image using the specified positional gravity to determine the location of the image being composited.
[i]Arguments[/i]:
Image -- A Draft.Image that will be composited with the image on which this function was invoked.
Gravity -- A Draft.PositionalGravity enum value used to determine the location of the image being composited.
Operation -- A Draft.CompositeOperator enum value indicatingoperation to perform
[i]Usage[/i]:
[code]someImage = Draft.Image.CreateImage( 800, 600 )
someOtherImage = Draft.Image.ReadFromFile( “//path/to/some/image/file.png” )
someImage.CompositeWithGravity( someOtherImage, Draft.PositionalGravity.NorthWestGravity, Draft.CompositeOperator.OverCompositeOp )[/code]
[b]CompositeWithPositionAndAnchor[/b]
[i]Type[/i]: Member
[i]Description[/i]: Composites an image with the current image at the given location using the specified compositing operation and positional anchor.
[i]Arguments[/i]:
Image -- A Draft.Image that will be composited with the image on which this function was invoked.
Left -- A float value that denotes how far from the left (as a percentage of the width) the composite operation should take place.
Bottom -- A float value that denotes how far from the bottom (as a percentage of the height) the composite operation should take place.
Anchor -- A Draft.Anchor enum value used to determine the location of the image being composited. The Anchor specifies which location of the image being composited will be anchored at the location specified by (Left, Bottom).
Operation -- A Draft.CompositeOperator enum value indicatingoperation to perform.
[i]Usage[/i]:
[code]someImage = Draft.Image.CreateImage( 800, 600 )
someOtherImage = Draft.Image.ReadFromFile( “//path/to/some/image/file.png” )
someImage.CompositeWithPositionAndAnchor( someOtherImage, 0, 0.66, Draft.Anchor.NorthWest, Draft.CompositeOperator.OverCompositeOp )[/code]
[b]CompositeWithPositionAndGravity[/b]
[i]Type[/i]: Member
[i]Description[/i]: Deprecated. Please see CompositeWithPositionAndAnchor instead. Composites an image with the current image at the given location using the specified compositing operation and positional gravity.
[i]Arguments[/i]:
Image -- A Draft.Image that will be composited with the image on which this function was invoked.
Left -- A float value that denotes how far from the left the composite operation should take place.
Bottom -- A float value that denotes how far from the bottom the composite operation should take place.
Gravity -- A Draft.PositionalGravity enum value used to determine the location of the image being composited.
Operation -- A Draft.CompositeOperator enum value indicatingoperation to perform.
[i]Usage[/i]:
[code]someImage = Draft.Image.CreateImage( 800, 600 )
someOtherImage = Draft.Image.ReadFromFile( “//path/to/some/image/file.png” )
someImage.CompositeWithPositionAndGravity( someOtherImage, 0, 0.66, Draft.PositionalGravity.NorthWestGravity, Draft.CompositeOperator.OverCompositeOp )[/code]
[b]Premultiply[/b]
[i]Type[/i]: Member
[i]Description[/i]: Premultiply the image's R, G, and B channels by the A (alpha) channel. The image is modified in-place.
[i]Arguments[/i]: (none)
[i]Usage[/i]:
[code]someImage = Draft.Image.ReadFromFile( "//path/to/some/image/file.png" )
someImage.Premultiply()[/code]
[b]Unpremultiply[/b]
[i]Type[/i]: Member
[i]Description[/i]: Unpremultiply the image's R, G, and B channels by the A (alpha) channel. The image is modified in-place.
[i]Arguments[/i]: (none)
[i]Usage[/i]:
[code]someImage = Draft.Image.ReadFromFile( "//path/to/some/image/file.png" )
someImage.Unpremultiply()[/code][/*:m][/list:u]
Draft.LUT
The Draft.LUT class contains Draft’s methods for working with Color Look-Up Tables (LUT). It contains two types of functions: Static functions, and Member functions. Static functions can be invoked without an instance (by calling Draft.LUT.), whereas Member functions must be invoked from an instance of a Draft.LUT object (by calling .).
The Static functions are used to create new instances of the Draft.LUT class, whereas the Member functions are used to work with existing instances of the Draft.LUT. The sample code snippets should clarify this distinction function in case you are unsure.
Draft.LUT Static Functions:
CreateCineon
Type: Static
Description: Return a new linear-to-Cineon LUT.
Arguments:
[list]blackLevel – Optional. An integer value in the range [0…1023] indicating the black level. Defaults to 95.
whiteLevel – Optional. An integer value in the range [0…1023] indicating the white level. Defaults to 685.
Usage:
cineonLut = Draft.LUT.CreateCineon()
[b]CreateAlexaV3LogC[/b]
[i]Type[/i]: Static
[i]Description[/i]: Return a new linear-to-Alexa V3 Log C LUT.
[i]Arguments[/i]: (none)
[i]Usage[/i]:
[code]
alexaLut = Draft.LUT.CreateAlexaV3LogC()
[/code]
[b]CreateSRGB[/b]
[i]Type[/i]: Static
[i]Description[/i]: Return a new linear-to-sRGB LUT.
[i]Arguments[/i]: (none)
[i]Usage[/i]:
[code]
srgbLut = Draft.LUT.CreateSRGB()
[/code]
[b]CreateRec709[/b]
[i]Type[/i]: Static
[i]Description[/i]: Return a new linear-to-Rec. 709 LUT.
[i]Arguments[/i]: (none)
[i]Usage[/i]:
[code]
rec709Lut = Draft.LUT.CreateRec709()
[/code]
[b]CreateGamma[/b]
[i]Type[/i]: Static
[i]Description[/i]: Return a new linear-to-Gamma LUT.
[i]Arguments[/i]:
gamma -- A float value indicating the gamma to apply.
[i]Usage[/i]:
[code]
gammaLut = Draft.LUT.CreateGamma(2.2)
[/code][/list:u]
Draft.LUT Member Functions
Apply
Type: Member
Description: Transform a Draft.Image’s color using this LUT.
Arguments:
[list]image – The image to transform. The image will be transformed in-place.
Usage:
image = Draft.Image.ReadFromFile( '//path/to/some/image/file.png' )
lut = Draft.LUT.CreateSRGB()
lut.Apply( image )
[b]Inverse[/b]
[i]Type[/i]: Member
[i]Description[/i]: Return a new LUT that performs the inverse operation of this LUT.
[i]Arguments[/i]: (none)
[i]Usage[/i]:
[code]cineonLut = Draft.LUT.CreateCineon()
inverseCineonLut = cineonLut.Inverse()[/code][/list:u]
Draft Video Classes/Functions
These classes and functions relate to either encoding or decoding video content.
QTFastStart
Type: Function
Description: Rearranges the atoms inside the input QT file to enable playback without first loading the entire file.
Arguments:
[list]InputFile – The filename of the input .mov file
OutputFile – The filename of the output .mov file
Usage:
Draft.QTFastStart( "/path/to/input.mov", "/path/to/output.mov" )
VideoDecoder
Type: Class
Constructor Arguments:
Filename – A string value indicating where the Video to decode can be found.
Properties:
fps -- The average frame rate of the video.
width -- The width of a video frame.
height -- The height of a video frame.
Member Functions:
[b]DecodeNextFrame[/b]
[i]Description[/i]: Decodes a frame from the video and returns it by reference through the Image argument. This function returns a boolean to indicate whether or not the decode succeeded.
[i]Arguments[/i]:
[list]Image -- A Draft image object used to return the decoded frame.
[i]Usage[/i]:
[code]decoder = Draft.VideoDecoder( "//path/to/video/file.mov" )
frameImage = Draft.Image.CreateImage( 800, 600 )
while( decoder.DecodeNextFrame( frameImage ) ):
#process the decoded frames here[/code]
[b]DecodeFrame[/b]
[i]Description[/i]: Decodes a specified frame from the video and returns it by reference through the Image argument. This function returns a boolean to indicate whether or not the decode succeeded.
[i]Arguments[/i]:
FrameNumber -- An integer indicating which frame should be decoded.
Image -- A Draft image object used to return the decoded frame.
[i]Usage[/i]:
[code]decoder = Draft.VideoDecoder( "//path/to/video/file.mov" )
frameImage = Draft.Image.CreateImage( 800, 600 )
if decoder.DecodeFrame( 100, frameImage ):
#Process frameImage here…[/code]
[/list:u]
VideoEncoder
Type: Class
Constructor Arguments:
filename – A string value indicating where the video file should be saved.
fps – Optional. An integer, float, or Fraction value indicating the framerate to use. Default is 24.
width – Optional. An integer value indicating the width to use. Default is 640.
height – Optional. An integer value indicating the height to use. Default is 480.
kbitRate – Optional. An integer value indicating the kbit rate to use. Default is None, which corresponds to quality = 85.
codec – Optional. A string value indicating the Codec to use. Default is ‘MJPEG’. Valid codec values are: ‘MPEG4’, ‘MJPEG’, ‘DNXHD’, ‘H264’, ‘PRORES’, and ‘RAWVIDEO’.
audioFilename – Optional. A string value indicating the file name of an audio file to include in the video. This can be an empty string for no audio file. Default is ‘’.
audioDelay – Optional. An integer value indicating the delay to apply to the audio file, measured in frames. Default is 0.
Named arguments:
quality – An integer in the range [0…100] indicating the video encoding quality to use. Greater values correspond to higher quality. Only one of quality or kbitRate can be specified.
Usage:
encoder = Draft.VideoEncoder( "//path/to/video/save.mov" )
- or, to specify the frame rate and frame size -
encoder = Draft.VideoEncoder( "//path/to/video/save.mov", 24, 800, 600 )
- or, to include an audio file -
encoder = Draft.VideoEncoder( "//path/to/video/save.mov", audioFilename='//path/to/audio/load.wav' )
- or, to use a specific quality and codec -
encoder = Draft.VideoEncoder( "//path/to/video/save.mov", quality=80, codec='H264' )
Member Functions:
EncodeNextFrame
Description: Encodes a given draft image as the next frame in the video.
Arguments:
[list]Image – The image to encode into the next frame of the video
Usage:
defaultEncoder = Draft.VideoEncoder( "//path/to/video/save.mov" )
defaultEncoder.EncodeNextFrame( Draft.Image.CreateImage( 800, 600 ) )
[b]FinalizeEncoding[/b]
[i]Description[/i]: Finalizes the encoding process, completing the video.
[i]Arguments[/i]: (none)
[i]Usage[/i]:
encoder = Draft.VideoEncoder( "//path/to/video.mov", 29, 800, 600, 5120, "MJPEG" )
#encode some frames here...
encoder.FinalizeEncoding()
- or, to use a Fraction FPS -
from fractions import Fraction
fps = Fraction(30000, 1001)
encoder = Draft.VideoEncoder( "//path/to/video.mov", fps, 800, 600, 5120, "MJPEG" )
[/list:u][/list:u]
LibraryInfo
These functions provide information about the Draft library itself.
About
Description: This function returns a string containing information about Draft, and its contributors.
Sample Code:
print Draft.LibraryInfo.About()
Version
Description: This function returns a string containing the version of the Draft library being used.
Sample Code:
print Draft.LibraryInfo.Version()
Cheers,