pygrafix.image — Working with image files

This module is used for loading images into a format pygrafix can understand.

pygrafix.image.load(filename[, file[, decoder]])

Loads an image from a file. If file is passed filename will be used as a hint for the filetype. Optionally you can specify a decoder argument which will be used for decoding the image, for more information about decoders read pygrafix.image.codecs. Returns a Texture object.

class pygrafix.image.Texture(internal_texture[, region])

Creates a Texture object from an InternalTexture object. Normally you shouldn’t have to create Texture objects yourself, use load() instead. The optional region argument is the region to use, this defaults to (0, 0, internal_texture.width, internal_texture.height).

width

The width of the texture. Note that when the region attribute is set that this will return the width of the region. To get the actual texture width use internal_texture.width. Read-only.

height

The height of the texture. Note that when the region attribute is set that this will return the height of the region. To get the actual texture width use internal_texture.height. Read-only.

region

A tuple in the form (x, y, width, height) that describes a region of the internal texture that gets represented by this texture. Read-write.

internal_texture

The internal texture used for this texture. Read-only.

copy([lazycopy])

Returns a copy of this texture. If lazycopy is True this function equals texture.get_region(0, 0, texture.width, texture.height). lazycopy is False by default.

get_region([x[, y[, width[, height]]]])

Returns a Texture object that represents a region of this texture, starting (x, y) pixels from the topleft of this texture, spanning (width, height) pixels. Any changes to the original texture will be represented in this region too, use texture.copy().get_region(...) if that’s undesired behaviour.

class pygrafix.image.InternalTexture(imgdata)

Creates a InternalTexture object from an ImageData object. Normally you shouldn’t have to create InternalTexture objects yourself, use load() instead.

width

The width of the texture. Read-only.

height

The height of the texture. Read-only.

class pygrafix.image.ImageData(width, height, format, data)

The format used to represent raw image data. format can be any of “RGBA”, “RGB”, “LA”, “A”. Data must be bytes data given in the format described. Only 8-bit channels are supported.

Project Versions

Previous topic

pygrafix.draw — Functions for drawing shapes

Next topic

pygrafix.image.codecs — Managing codecs

This Page