The module provides some vector drawing functions.
New in version 0.3.0.
(collections.Sequence) The list of clip path units
(collections.Sequence) The list of fill-rule types.
(collections.Sequence) The attribute names of font metrics.
(collections.Sequence) The list of text gravity types.
(collections.Sequence) The list of LineCap types
(collections.Sequence) The list of LineJoin types
(collections.Sequence) The list of paint method types.
(collections.Sequence) The list of stretch types for fonts
(collections.Sequence) The list of style types for fonts
(collections.Sequence) The list of text align types.
(collections.Sequence) The list of text decoration types.
(collections.Sequence) The list of text direction types.
Drawing object. It maintains several vector drawing instructions and can get drawn into zero or more Image objects by calling it.
For example, the following code draws a diagonal line to the image:
with Drawing() as draw:
draw.line((0, 0), image.size)
draw(image)
Parameters: | drawing (Drawing) – an optional drawing object to clone. use clone() method rather than this parameter |
---|
New in version 0.3.0.
Adjusts the current affine transformation matrix with the specified affine transformation matrix. Note that the current affine transform is adjusted rather than replaced.
| sx rx 0 |
| x', y', 1 | = | x, y, 1 | * | ry sy 0 |
| tx ty 1 |
Parameters: | matrix (Sequence) – a list of Real to define affine matrix. [sx, rx, ry, sy, tx, ty] |
---|
New in version 0.4.0.
Draws a arc using the current stroke_color, stroke_width, and fill_color.
Parameters: |
|
---|
New in version 0.4.0.
Draws a bezier curve through a set of points on the image, using the specified array of coordinates.
At least four points should be given to complete a bezier path. The first & forth point being the start & end point, and the second & third point controlling the direction & curve.
Example bezier on image
with Drawing() as draw:
points = [(40,10), # Start point
(20,50), # First control
(90,10), # Second control
(70,40)] # End point
draw.stroke_color = Color('#000')
draw.fill_color = Color('#fff')
draw.bezier(points)
draw.draw(image)
Parameters: | points (list) – list of x,y tuples |
---|
New in version 0.4.0.
(Color) the current border color. It also can be set. This attribute controls the behavior of color() during 'filltoborder' operation.
New in version 0.4.0.
Draws a circle from origin to perimeter
Parameters: |
|
---|
New in version 0.4.0.
(basestring) The current clip rule. It also can be set. It’s a string value from FILL_RULE_TYPES list.
New in version 0.4.0.
(basestring) The current clip units. It also can be set. It’s a string value from CLIP_PATH_UNITS list.
New in version 0.4.0.
Draws a color on the image using current fill color, starting at specified position & method.
Available methods in wand.drawing.PAINT_METHOD_TYPES:
New in version 0.4.0.
Adds a comment to the vector stream.
Parameters: | message (basestring) – the comment to set. |
---|
New in version 0.4.0.
Composites an image onto the current image, using the specified composition operator, specified position, and at the specified size.
Parameters: |
|
---|
New in version 0.4.0.
Renders the current drawing into the image. You can simply call Drawing instance rather than calling this method. That means the following code which calls Drawing object itself:
drawing(image)
is equivalent to the following code which calls draw() method:
drawing.draw(image)
Parameters: | image (Image) – the image to be drawn |
---|
Draws a ellipse at origin with independent x & y radius. Ellipse can be partial by setting start & end rotation.
Parameters: |
|
---|
New in version 0.4.0.
(basestring) The current fill rule. It can also be set. It’s a string value from FILL_RULE_TYPES list.
New in version 0.4.0.
(numbers.Real) The font size. It also can be set.
(basestring) The current font family. It also can be set.
New in version 0.4.0.
(basestring) The current font style. It also can be set.
New in version 0.4.0.
Queries font metrics from the given text.
Parameters: |
|
---|
(basestring) The text placement gravity used when annotating with text. It’s a string from GRAVITY_TYPES list. It also can be set.
Draws a line start to end.
Parameters: |
|
---|
Paints on the image’s opacity channel in order to set effected pixels to transparent.
To influence the opacity of pixels. The available methods are:
New in version 0.4.0.
(Real) returns the opacity used when drawing with the fill or stroke color or texture. Fully opaque is 1.0. This method only affects vector graphics, and is experimental. To set the opacity of a drawing, use Drawing.fill_opacity & Drawing.stroke_opacity
New in version 0.4.0.
Adds a path element to the current path which closes the current subpath by drawing a straight line from the current point to the current subpath’s most recent starting point.
New in version 0.4.0.
Draws a cubic Bezier curve from the current point to given to (x,y) coordinate using controls points at the beginning & end of the curve. If smooth is set to True, only one controls is expected and the previous control is used, else two pair of coordinates are expected to define the control points. The to coordinate then becomes the new current point.
Parameters: |
|
---|
New in version 0.4.0.
Draws a quadratic Bezier curve from the current point to given to coordinate. The control point is assumed to be the reflection of the control point on the previous command if smooth is True, else a pair of control coordinates must be given. Each` coordinates can be relative, or absolute, to the current point by setting the relative flag. The to coordinate then becomes the new current point, and the control coordinate will be assumed when called again when smooth is set to true.
Parameters: |
|
---|
New in version 0.4.0.
Draws an elliptical arc from the current point to given to coordinates. The to coordinates can be relative, or absolute, to the current point by setting the relative flag. The size and orientation of the ellipse are defined by two radii (rx, ry) in radius and an rotation parameters, which indicates how the ellipse as a whole is rotated relative to the current coordinate system. The center of the ellipse is calculated automagically to satisfy the constraints imposed by the other parameters. large_arc and clockwise contribute to the automatic calculations and help determine how the arc is drawn. If large_arc is True then draw the larger of the available arcs. If clockwise is true, then draw the arc matching a clock-wise rotation.
Parameters: |
|
---|
New in version 0.4.0.
Terminates the current path.
New in version 0.4.0.
Draws a horizontal line path from the current point to the target point. Given x parameter can be relative, or absolute, to the current point by setting the relative flag. The target point then becomes the new current point.
Parameters: |
---|
New in version 0.4.0.
Draws a line path from the current point to the given to coordinate. The to coordinates can be relative, or absolute, to the current point by setting the relative flag. The coordinate then becomes the new current point.
Parameters: |
|
---|
New in version 0.4.0.
Starts a new sub-path at the given coordinates. Given to parameter can be relative, or absolute, by setting the relative flag.
Parameters: |
|
---|
New in version 0.4.0.
Declares the start of a path drawing list which is terminated by a matching path_finish() command. All other path_* commands must be enclosed between a path_start() and a path_finish() command. This is because path drawing commands are subordinate commands and they do not function by themselves.
New in version 0.4.0.
Draws a vertical line path from the current point to the target point. Given y parameter can be relative, or absolute, to the current point by setting the relative flag. The target point then becomes the new current point.
Parameters: |
---|
New in version 0.4.0.
Draws a point at given x and y
Parameters: |
---|
New in version 0.4.0.
Draws a polygon using the current stoke_color, stroke_width, and fill_color, using the specified array of coordinates.
Example polygon on image
with Drawing() as draw:
points = [(40,10), (20,50), (90,10), (70,40)]
draw.polygon(points)
draw.draw(image)
Parameters: | points (list) – list of x,y tuples |
---|
New in version 0.4.0.
Draws a polyline using the current stoke_color, stroke_width, and fill_color, using the specified array of coordinates.
Identical to polygon, but without closed stroke line.
Parameters: | points (list) – list of x,y tuples |
---|
New in version 0.4.0.
Pop destroys the current drawing wand and returns to the previously pushed drawing wand. Multiple drawing wands may exist. It is an error to attempt to pop more drawing wands than have been pushed, and it is proper form to pop all drawing wands which have been pushed.
Returns: | success of pop operation |
---|---|
Return type: | bool |
New in version 0.4.0.
Terminates a clip path definition.
New in version 0.4.0.
Terminates a definition list.
New in version 0.4.0.
Terminates a pattern definition.
New in version 0.4.0.
Push clones the current drawing wand to create a new drawing wand. The original drawing wand(s) may be returned to by invoking Drawing.pop. The drawing wands are stored on a drawing wand stack. For every Pop there must have already been an equivalent Push.
Returns: | success of push operation |
---|---|
Return type: | bool |
New in version 0.4.0.
Starts a clip path definition which is comprised of any number of drawing commands and terminated by a Drawing.pop_clip_path command.
Parameters: | clip_mask_id (basestring) – string identifier to associate with the clip path. |
---|
New in version 0.4.0.
Indicates that commands up to a terminating Drawing.pop_defs command create named elements (e.g. clip-paths, textures, etc.) which may safely be processed earlier for the sake of efficiency.
New in version 0.4.0.
Indicates that subsequent commands up to a Drawing.pop_pattern command comprise the definition of a named pattern. The pattern space is assigned top left corner coordinates, a width and height, and becomes its own drawing space. Anything which can be drawn may be used in a pattern definition. Named patterns may be used as stroke or brush definitions.
Parameters: |
|
---|---|
Returns: | success of push operation |
Return type: | bool |
New in version 0.4.0.
Draws a rectangle using the current stoke_color, stroke_width, and fill_color.
+--------------------------------------------------+
| ^ ^ |
| | | |
| top | |
| | | |
| v | |
| <-- left --> +-------------------+ bottom |
| | ^ | | |
| | <-- width --|---> | | |
| | height | | |
| | | | | |
| | v | | |
| +-------------------+ v |
| <--------------- right ----------> |
+--------------------------------------------------+
Parameters: |
|
---|
New in version 0.3.6.
Changed in version 0.4.0: Radius keywords added to create rounded rectangle.
Applies the specified rotation to the current coordinate space.
Parameters: | degree (Real) – degree to rotate |
---|
New in version 0.4.0.
Adjusts the scaling factor to apply in the horizontal and vertical directions to the current coordinate space.
Parameters: |
---|
New in version 0.4.0.
Sets the URL to use as a fill pattern for filling objects. Only local URLs (“#identifier”) are supported at this time. These local URLs are normally created by defining a named fill pattern with Drawing.push_pattern & Drawing.pop_pattern.
Parameters: | url (basestring) – URL to use to obtain fill pattern. |
---|
New in version 0.4.0.
Sets the pattern used for stroking object outlines. Only local URLs (“#identifier”) are supported at this time. These local URLs are normally created by defining a named stroke pattern with Drawing.push_pattern & Drawing.pop_pattern.
Parameters: | url (basestring) – URL to use to obtain stroke pattern. |
---|
New in version 0.4.0.
Skews the current coordinate system in the horizontal direction if x is given, and vertical direction if y is given.
Parameters: |
---|
New in version 0.4.0.
(bool) Controls whether stroked outlines are antialiased. Stroked outlines are antialiased by default. When antialiasing is disabled stroked pixels are thresholded to determine if the stroke color or underlying canvas color should be used.
It also can be set.
New in version 0.4.0.
(Sequence) - (numbers.Real) An array representing the pattern of dashes & gaps used to stroke paths. It also can be set.
New in version 0.4.0.
(numbers.Real) The stroke dash offset. It also can be set.
New in version 0.4.0.
(basestring) The stroke line cap. It also can be set.
New in version 0.4.0.
(basestring) The stroke line join. It also can be set.
New in version 0.4.0.
(numbers.Real) The stroke width. It also can be set.
New in version 0.3.3.
Writes a text body into (x, y).
Parameters: |
|
---|
(basestring) The current text alignment setting. It’s a string value from TEXT_ALIGN_TYPES list. It also can be set.
(bool) The boolean value which represents whether antialiasing is used for text rendering. It also can be set to True or False to switch the setting.
(basestring) The text decoration setting, a string from TEXT_DECORATION_TYPES list. It also can be set.
(basestring) The text direction setting. a string from TEXT_DIRECTION_TYPES list. It also can be set.
(numbers.Real) The setting of the text line spacing. It also can be set.
(numbers.Real) The setting of the word spacing. It also can be set.
(numbers.Real) The setting of the text kerning. It also can be set.
(Color) The color of a background rectangle to place under text annotations. It also can be set.
Applies a translation to the current coordinate system which moves the coordinate system origin to the specified coordinate.
Parameters: |
---|
New in version 0.4.0.
(basestring) The XML text of the Vector Graphics. It also can be set. The drawing-wand XML is experimental, and subject to change.
Setting this property to None will reset all vector graphic properties to the default state.
New in version 0.4.0.
Viewbox sets the overall canvas size to be recorded with the drawing vector data. Usually this will be specified using the same size as the canvas image. When the vector data is saved to SVG or MVG formats, the viewbox is use to specify the size of the canvas image that a viewer will render the vector data on.
Parameters: |
---|
New in version 0.4.0.
The tuple subtype which consists of font metrics data.
Alias for field number 2
Alias for field number 1
Alias for field number 0
Alias for field number 3
Alias for field number 6
Alias for field number 5
Alias for field number 4
Alias for field number 11
Alias for field number 7
Alias for field number 9
Alias for field number 12
Alias for field number 8
Alias for field number 10