pyspng.load

pyspng.load(data: bytes, format: Optional[str] = None)numpy.ndarray

Load a PNG from a bytes object and return the image data as a np.ndarray.

The output format, if specified, can be one of “L”, “LA”, “RGB”, “RGBA”. If left unspecified, automatically determine it by looking at the PNG ihdr block.

Parameters
  • data (bytes) – PNG data

  • format (str, optional) – Output pixel format. Auto-detect if None.

Returns

Image data as a numpy array.

The resulting array will have shape [height,width,channels] if channels > 1, or [height,width] for grayscale images.

The array dtype is either np.uint8 or np.uint16, depending the desired output format, or if unspecified, depending on PNG contents.

Return type

numpy.ndarray