Open the given image file
Uses preferred_image_class.
Parameters: |
|
---|---|
Returns: | An Image |
Note that the file is not opened until needed. This makes it possible to use maps and tilesets that refer to nonexistent images.
The type of the object open() returns depends on the installed libraries. If Pillow (or PIL) is installed, the faster PilImage is used; otherwise tmxlib falls back to PngImage, which works anywhere but may be lower and only supports PNG files. Both wrappers offer the same API.
A list of all available image classes, listed by preference. preferred_image_class is the first element in this list.
Image base class
This defines the basic image API, shared by Image and ImageRegion.
Pixels are represented as (r, g, b, a) float tuples, with components in the range of 0 to 1.
Get a pixel or region
With a pair of integers, this returns a pixel via get_pixel():
Parameters: | pos – pair of integers, (x, y) |
---|---|
Returns: | pixel at (x, y) as a (r, g, b, a) float tuple |
With a pair of slices, returns a sub-image:
Parameters: | pos – pair of slices, (left:right, top:bottom) |
---|---|
Returns: | a ImageRegion |
An image. Conceptually, an 2D array of pixels.
Note
This is an abstract base class. Use tmxlib.image.open() or tmxlib.image.preferred_image_class to get a usable subclass.
init arguments that become attributes:
- size[source]¶
Size of the image, in pixels.
If given in constructor, the image doesn’t have to be decoded to get this information, somewhat speeding up operations that don’t require pixel access.
If it’s given in constructor and it does not equal the actual image size, an exception will be raised as soon as the image is decoded.
- source¶
The file name of this image, if it is to be saved separately from maps/tilesets that use it.
- trans¶
A color key used for transparency
Note
Currently, loading images that use color-key transparency is very inefficient. If possible, use the alpha channel instead.
Images support indexing (img[x, y]); see tmxlib.image_base.ImageBase.__getitem__()
Get the color of the pixel at position (x, y) as a RGBA 4-tuple.
Supports negative indices by wrapping around in the obvious way.
Methods interesting for subclassers: