image_utils module

Various utilities for working with Pillow images

mip_sizes(dimensions: Tuple[int, int], mip_count: Optional[int] = None) List[Tuple[int, int]]

Create a chain of mipmap sizes for a given source source size, where each source is half the size of the one before. Note that the division by 2 rounds down. So a 63x63 texture has as its next lowest mipmap level 31x31. And so on.

See the OpenGL wiki page on mipmaps for more info.

Parameters
  • dimensions – Size of the source source in pixels

  • mip_count – Number of mipmap sizes to generate. By default, generate until the last mip level is 1x1. Resulting mip chain will be smaller if a 1x1 mip level is reached before this value.

Returns

A list of 2-tuples representing the dimensions of each mip level, including dimensions at element 0.

resize_no_premultiply(image: PIL.Image.Image, size: Tuple[int, int]) PIL.Image.Image

Resize an image without premulitplying the alpha. Required due to a quick in Pillow

Parameters
  • image – Image to resize

  • size – Size to resize to

Returns

The resized image