wand.drawing — Drawings

The module provides some vector drawing functions.

New in version 0.3.0.

wand.drawing.FONT_METRICS_ATTRIBUTES = ('character_width', 'character_height', 'ascender', 'descender', 'text_width', 'text_height', 'maximum_horizontal_advance', 'x1', 'y1', 'x2', 'y2', 'x', 'y')

(collections.Sequence) The attribute names of font metrics.

wand.drawing.TEXT_ALIGN_TYPES = ('undefined', 'left', 'center', 'right')

(collections.Sequence) The list of text align types.

  • 'undefined'
  • 'left'
  • 'center'
  • 'right'
wand.drawing.TEXT_DECORATION_TYPES = ('undefined', 'no', 'underline', 'overline', 'line_through')

(collections.Sequence) The list of text decoration types.

  • 'undefined'
  • 'no'
  • 'underline'
  • 'overline'
  • 'line_through'
wand.drawing.GRAVITY_TYPES = ('forget', 'north_west', 'north', 'north_east', 'west', 'center', 'east', 'south_west', 'south', 'south_east', 'static')

(collections.Sequence) The list of text gravity types.

  • 'forget'
  • 'north_west'
  • 'north'
  • 'north_east'
  • 'west'
  • 'center'
  • 'east'
  • 'south_west'
  • 'south'
  • 'south_east'
  • 'static'
class wand.drawing.Drawing(drawing=None)

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 rathan than this parameter

New in version 0.3.0.

clone()

Copies a drawing object.

Returns:a duplication
Return type:Drawing
draw(image)

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
fill_color

(Color) The current color to fill. It also can be set.

font

(basestring) The current font name. It also can be set.

font_size

(numbers.Real) The font size. It also can be set.

get_font_metrics(image, text, multiline=False)

Queries font metrics from the given text.

Parameters:
  • image (Image) – the image to be drawn
  • text (basestring) – the text string for get font metrics.
  • multiline (boolean) – text is multiline or not
gravity

(basestring) The text placement gravity used when annotating with text. It’s a string from GRAVITY_TYPES list. It also can be set.

line(start, end)

Draws a line start to end.

Parameters:
stroke_color

(Color) The current color of stroke. It also can be set.

New in version 0.3.3.

stroke_width

(numbers.Real) The stroke width. It also can be set.

New in version 0.3.3.

text(x, y, body)

Writes a text body into (x, y).

Parameters:
  • x (numbers.Integral) – the left offset where to start writing a text
  • y (numbers.Integral) – the top offset where to start writing a text
  • body (basestring) – the body string to write
text_alignment

(basestring) The current text alignment setting. It’s a string value from TEXT_ALIGN_TYPES list. It also can be set.

text_antialias

(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.

text_decoration

(basestring) The text decoration setting, a string from TEXT_DECORATION_TYPES list. It also can be set.

text_encoding

(basestring) The internally used text encoding setting. Although it also can be set, but it’s not encorouged.

text_interline_spacing

(numbers.Real) The setting of the text line spacing. It also can be set.

text_interword_spacing

(numbers.Real) The setting of the word spacing. It also can be set.

text_kerning

(numbers.Real) The setting of the text kerning. It also can be set.

text_under_color

(Color) The color of a background rectangle to place under text annotations. It also can be set.

class wand.drawing.FontMetrics

The tuple subtype which consists of font metrics data.

ascender

Alias for field number 2

character_height

Alias for field number 1

character_width

Alias for field number 0

descender

Alias for field number 3

maximum_horizontal_advance

Alias for field number 6

text_height

Alias for field number 5

text_width

Alias for field number 4

x

Alias for field number 11

x1

Alias for field number 7

x2

Alias for field number 9

y

Alias for field number 12

y1

Alias for field number 8

y2

Alias for field number 10

Related Topics

This Page