django-utils v0.3.0 documentation

This Page

Images

Uses the Python Imaging Library to provide methods for working with images.

Note

requires PIL

djutils.utils.images.resize(source_file, target_filename, new_width, new_height=None)

Resize or scale an image. Returns the width and height after resizing.

Parameters:
  • source_file – the path to the source image
  • target_filename – the path to store the resized image (can be same as source_file)
  • new_width – width to resize image to
  • new_height – height to resize image to, if not provided, will be calculated in proportion to new_width
djutils.utils.images.crop(source_file, target_filename, x, y, w, h)

Extract part of an existing Image file and save in a new file.