image

Image encoding helpers.

async pipecat.utils.image.encode_image(image: bytes, size: tuple[int, int], format: str | None) → tuple[bytes, str][source]

Encode an image for a model to look at.

An image whose format is a MIME type is already encoded and keeps its bytes. Raw pixels are encoded as a JPEG in a thread.

Parameters:
  • image – The image bytes, raw pixels or already encoded.

  • size – The image’s width and height.

  • format – The pixel format, such as "RGB" or "RGBA", or the MIME type of an encoded image. Raw pixels are taken as RGB when not given.

Returns:

The encoded bytes and their MIME type.