Skip to main content
Vane Data / Reference

encode_image

encode_image encodes an IMAGE into an image file format and returns the bytes.

Signature

example.py
vane.encode_image(image, image_format) -> Expression

SQL: encode_image(image, format). Expression method: expr.encode_image(image_format).

Parameters

NameTypeDescriptionDefault
imageIMAGE value or ExpressionInput imageRequired
image_formatImageFormat member, format string, or ExpressionPNG, JPEG, TIFF, GIF, or BMP under the mode matrix belowRequired

encode_image follows an explicit mode matrix: PNG accepts all eight integer modes; TIFF accepts all ten; JPEG accepts L/RGB; GIF accepts L/RGB with at most 256 palette colors; BMP accepts L/RGB. Use convert_image first for other combinations.

Returns and errors

Returns encoded BLOB bytes. NULL image or format returns NULL. Unsupported formats, and mode/format combinations outside the matrix, raise.

Example

example.py
import vane


con = vane.connect()
con.sql("""
    SELECT encode_image(
        crop(decode_image_file(image_file('photo.png')), [10, 20, 64, 48]),
        'PNG'
    ) AS thumbnail
""").show()