Images

The reduce_image_size() function uses the Python Imaging Library (PIL) to create a smaller version of an image.

You can scale images down to a specified width and height or by a scale factor.

indieweb_utils.reduce_image_size(url=None, image_data=None, pil_image=None, reduction_size=0.5, height=None, width=None)[source]

Reduce the size of an image. Returns a PIL.Image object. Useful for creating images for use in HTML source sets.

Parameters:
  • url (str) – The URL of the image (optional).

  • image_data (bytes) – The image data in bytes (optional).

  • pil_image (PIL.Image) – The PIL.Image object (optional).

  • reduction_size (float) – The scale factor by which to reduce the image, expressed as a number between 0 and 1. (i.e. 0.5 = 50%)

Returns:

The reduced image data.

Return type:

PIL.Image

Example:

from indieweb_utils.images import reduce_image_size

reduced_image_data = reduce_image_size(image_data)