image module

API Docs

The image module allows you to manipulate images in your Anvil app. Begin by importing the anvil.image module.

Get dimensions

To get the width and height of an image, use get_dimensions:

import anvil.image

# The image can be any Media object containing an image
image_media = URLMedia('https://anvil.works/img/workshops-cogwheels.jpg')

width, height = anvil.image.get_dimensions(image_media)

print("The image is %s pixels wide and %s pixels high" % (width, height))

Generating thumbnails

To generate a thumbnail of an image (for uploading, for example) use the generate_thumbnail method.

# Resize the image to have a maximum dimension of 120px.
small_img = anvil.image.generate_thumbnail(image_media, 120)

Rotating

To rotate an image clockwise by some number of degrees, use the rotate method.

# Rotate the image by 30 degrees.

rotated_image = anvil.image.rotate(img, 30)