Skip to main content
Vane Data / Reference

crop

crop extracts an integer (x, y, width, height) window from an IMAGE. Pixels outside the input are zero-filled, including alpha channels.

Signature

example.py
vane.crop(image, bbox) -> Expression

SQL: crop(image, bbox). Expression method: expr.crop(bbox).

Parameters

NameTypeDescriptionDefault
imageIMAGE value or ExpressionInput imageRequired
bbox(x, y, width, height) integer tuple/list or ExpressionCrop origin with positive width and height; out-of-input pixels are zero-filledRequired

Returns and errors

Returns a dynamic IMAGE that retains the input's mode constraint. NULL image or bbox returns NULL. Negative or zero dimensions, missing elements, and implicit coordinate conversion raise.

Example

example.py
import vane


con = vane.connect()
image = con.sql("SELECT decode_image_file(image_file('photo.png'))").fetchone()[0]
con.sql("SELECT crop($1, [10, 20, 64, 48])", params=[vane.Value(image, vane.image_type())]).show()