Skip to content

ipygame.image

pygame-compatible image module.

FileLike = Union[str, Path, BinaryIO]

def load(file: FileLike, namehint: str = "") -> Surface

Load an image from a file path or file-like object.

def load_basic(file: FileLike) -> Surface

Load a BMP image.

def load_extended(file: FileLike, namehint: str = "") -> Surface

Load an image with extended format support.

def load_sized_svg(file: FileLike, size: tuple[int, int]) -> Surface

Load an SVG rasterized at the given size.

Requires the cairosvg package. Falls back to Pillow if available.

def save(surface: Surface, file: FileLike, namehint: str = "") -> None

Save a Surface to a file (PNG, JPEG, BMP, TGA).

def save_extended(surface: Surface,
file: FileLike,
namehint: str = "") -> None

Save a Surface using extended format support.

def get_extended() -> bool

Return True if extended image formats are available.

def get_sdl_image_version(linked: bool = True)

Return None — SDL_image is not used.

def tobytes(surface: Surface,
format: str = "RGBA",
flipped: bool = False,
pitch: int = -1) -> bytes

Transfer Surface pixels to a byte string.

def tostring(surface: Surface,
format: str = "RGBA",
flipped: bool = False,
pitch: int = -1) -> bytes

Deprecated — use tobytes.

def frombytes(data: bytes,
size: tuple[int, int],
format: str = "RGBA",
flipped: bool = False,
pitch: int = -1) -> Surface

Create a Surface from a byte buffer.

def fromstring(data: bytes,
size: tuple[int, int],
format: str = "RGBA",
flipped: bool = False,
pitch: int = -1) -> Surface

Deprecated — use frombytes.

def frombuffer(data,
size: tuple[int, int],
format: str = "RGBA",
pitch: int = -1) -> Surface

Create a Surface from a buffer object (data is copied).