sdl2.sdlimage - Python bindings for SDL_image

py-sdl2 provides bindings for SDL2_image, a library designed for use with SDL2 that adds support for loading a wide range of different common (and uncommon) image formats for easy use with SDL2. In addition, SDL2_image includes functions for saving SDL_Surface objects to PNG and/or JPEG images.

Note

If using an alternative rendering system that doesn’t use SDL surfaces as input (e.g. PyOpenGL), the Pillow imaging library may be a better fit for your project.

Initialization and library information functions

sdl2.sdlimage.IMG_GetError()

Returns the most recently encountered SDL2 error message, if any.

This function is a simple wrapper around SDL_GetError().

Retuns:A UTF-8 encoded string describing the most recent SDL2 error.
Return type:bytes
sdl2.sdlimage.IMG_SetError(fmt)

Sets the most recent SDL2 error message to a given string.

This function is a simple wrapper around SDL_SetError().

Parameters:fmt (bytes) – A UTF-8 encoded string containing the error message to set.
Retuns:Always returns -1.
Return type:int

Image format-checking functions

These functions are used to check whether an SDL file object (SDL_RWops) is a valid image file of a given format. Note that all of these functions will return 0 if SDL2_image was not built with support for that format, even if it is a valid image of that type, so be cautious when using these for formats like WEBP, JPEG, PNG, and TIFF, which are optional when building SDL2_image.

Module constants

sdl2.sdlimage.IMG_MAJOR_VERSION

Latest SDL2_image library major number supported by PySDL2.

sdl2.sdlimage.IMG_MINOR_VERSION

Latest SDL2_image library minor number supported by PySDL2.

sdl2.sdlimage.IMG_PATCHLEVEL

Latest SDL2_image library patch level number supported by PySDL2.

sdl2.sdlimage.IMG_INIT_JPG

IMG_Init() flag to enable support for the JPEG image format.

sdl2.sdlimage.IMG_INIT_PNG

IMG_Init() flag to enable support for the PNG image format.

sdl2.sdlimage.IMG_INIT_TIF

IMG_Init() flag to enable support for the TIFF image format.

sdl2.sdlimage.IMG_INIT_WEBP

IMG_Init() flag to enable support for the WEBP image format.