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.
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 (currently not implemented)
Images support indexing (img[x, y]) as a shortcut for the get_pixel and set_pixel methods.
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.
Set the color of the pixel at position (x, y) to a RGBA 4-tuple
Supports negative indices by wrapping around in the obvious way.
Methods interesting for subclassers:
Note
It’s currently not possible to save modified images.