ImageGrid Class

Inheritance diagram of ImageGrid

class ImageGrid(image, rows, columns, item_width=None, item_height=None, row_padding=0, column_padding=0)

An imaginary grid placed over an image allowing easy access to regular regions of that image.

The grid can be accessed either as a complete image, or as a sequence of images. The most useful applications are to access the grid as a TextureGrid:

image_grid = ImageGrid(...)
texture_grid = image_grid.get_texture_sequence()

or as a Texture3D:

image_grid = ImageGrid(...)
texture_3d = Texture3D.create_for_image_grid(image_grid)

Constructor:

__init__(image, rows, columns, item_width=None, item_height=None, row_padding=0, column_padding=0)

Construct a grid for the given image.

You can specify parameters for the grid, for example setting the padding between cells. Grids are always aligned to the bottom-left corner of the image.

Parameters:
  • image (AbstractImage) – Image over which to construct the grid.
  • rows (int) – Number of rows in the grid.
  • columns (int) – Number of columns in the grid.
  • item_width (int) – Width of each column. If unspecified, is calculated such that the entire image width is used.
  • item_height (int) – Height of each row. If unspecified, is calculated such that the entire image height is used.
  • row_padding (int) – Pixels separating adjacent rows. The padding is only inserted between rows, not at the edges of the grid.
  • column_padding (int) – Pixels separating adjacent columns. The padding is only inserted between columns, not at the edges of the grid.

Methods:

blit(x, y[, z]) Draw this image to the active framebuffers.
blit_into(source, x, y, z) Draw source on this image.
blit_to_texture(target, level, x, y[, z]) Draw this image on the currently bound texture at target.
get_animation(period[, loop]) Create an animation over this image sequence for the given constant framerate.
get_image_data()
get_mipmapped_texture() Retrieve a Texture instance with all mipmap levels filled in.
get_region(x, y, width, height) Retrieve a rectangular region of this image.
get_texture([rectangle, force_rectangle])
get_texture_sequence()
save([filename, file, encoder]) Save this image to a file.

Attributes:

anchor_x Type: int
anchor_y Type: int
image_data An ImageData view of this image.
mipmapped_texture A Texture view of this image.
texture Get a Texture view of this image.
texture_sequence Access this image sequence as a texture sequence.

Methods

ImageGrid.get_image_data()
ImageGrid.get_texture(rectangle=False, force_rectangle=False)
ImageGrid.get_texture_sequence()

Inherited members

Methods

ImageGrid.blit(x, y, z=0)

Draw this image to the active framebuffers.

The image will be drawn with the lower-left corner at (x - anchor_x, y - anchor_y, z).

ImageGrid.blit_into(source, x, y, z)

Draw source on this image.

source will be copied into this image such that its anchor point is aligned with the x and y parameters. If this image is a 3D texture, the z coordinate gives the image slice to copy into.

Note that if source is larger than this image (or the positioning would cause the copy to go out of bounds) then you must pass a region of source to this method, typically using get_region().

ImageGrid.blit_to_texture(target, level, x, y, z=0)

Draw this image on the currently bound texture at target.

This image is copied into the texture such that this image’s anchor point is aligned with the given x and y coordinates of the destination texture. If the currently bound texture is a 3D texture, the z coordinate gives the image slice to blit into.

ImageGrid.get_animation(period, loop=True)

Create an animation over this image sequence for the given constant framerate.

:Parameters
period : float
Number of seconds to display each frame.
loop : bool
If True, the animation will loop continuously.
Return type:Animation

Note

Since pyglet 1.1

ImageGrid.get_mipmapped_texture()

Retrieve a Texture instance with all mipmap levels filled in.

Requires that image dimensions be powers of 2.

Return type:Texture

Note

Since pyglet 1.1

ImageGrid.get_region(x, y, width, height)

Retrieve a rectangular region of this image.

Parameters:
  • x (int) – Left edge of region.
  • y (int) – Bottom edge of region.
  • width (int) – Width of region.
  • height (int) – Height of region.
Return type:

AbstractImage

ImageGrid.save(filename=None, file=None, encoder=None)

Save this image to a file.

Parameters:
  • filename (str) – Used to set the image file format, and to open the output file if file is unspecified.
  • file (file-like object or None) – File to write image data to.
  • encoder (ImageEncoder or None) – If unspecified, all encoders matching the filename extension are tried. If all fail, the exception from the first one attempted is raised.

Attributes

ImageGrid.anchor_x = 0
ImageGrid.anchor_y = 0
ImageGrid.image_data

An ImageData view of this image.

Changes to the returned instance may or may not be reflected in this image. Read-only.

Warning

Deprecated. Use get_image_data.

Type:ImageData
ImageGrid.mipmapped_texture

A Texture view of this image.

The returned Texture will have mipmaps filled in for all levels. Requires that image dimensions be powers of 2. Read-only.

Warning

Deprecated. Use get_mipmapped_texture.

Type:Texture
ImageGrid.texture

Get a Texture view of this image.

Changes to the returned instance may or may not be reflected in this image.

Warning

Deprecated. Use get_texture.

Type:Texture
ImageGrid.texture_sequence

Access this image sequence as a texture sequence.

Warning

Deprecated. Use get_texture_sequence

Type:TextureSequence

Table Of Contents

Previous topic

ImageDataRegion Class

Next topic

ImagePattern Class