The tmxlib.canvas and draw modules

Provides image drawing/modification capabilities

This module requires PIL (or Pillow) to be installed.

class tmxlib.canvas.Canvas(size=(0, 0), commands=(), color=(0, 0, 0, 0))[source]

A mutable image

Acts as a regular Image, except it allows modifications.

Some operations, such as taking an ImageRegion, will work on an immutable copy of the canvas.

Parameters:commands – An iterable of drawing commands to apply on the canvas right after creation

init arguments that become attributes:

size

The size of this Canvas. Will also available as width and height attributes.

color

The initial color the canvas will have

drawing methods:

draw_image(image, pos=(0, 0), opacity=1)[source]

Paste the given image at the given position

conversion:

to_image()[source]

Take an immutable copy of this Canvas

Returns an Image

internals:

pil_image

The PIL image underlying this Canvas.

Note

Modifying the returned image is not guaranteed to have an effect.

In the future there might be Canvas implementations not based on PIL; their pil_image attribute might only give a copy of the data. If PIL is not installed, the attribute won’t be present at all.

Drawing commands

Operations on a Canvas may be specified by command objects. This allows one to flexibly filter or modify a stream of drawing operations.

class tmxlib.draw.DrawCommand[source]

A draw command

draw(canvas)[source]

Apply this operation to the given Canvas

class tmxlib.draw.DrawImageCommand(image, pos=(0, 0), opacity=1)[source]

Command to draw an image

init arguments that become attributes:

image

The image to draw

pos

Position at which to draw the image. Will also available as x and y attributes.

Table Of Contents

Previous topic

The tmxlib.image modules

Next topic

The tmxlib.helpers module

This Page