transforms Module

class simpleimages.transforms.BasePILTransform[source]

Bases: object

Base transform object that provides helper methods to transform django.core.files.images.ImageFile using PIL.

Must subclass and override transform_pil_image().


Returns the transformed version of PIL.Image.Image

Uses transform_pil_image() to transform the PIL.Image.Image.

Parameters:original_django_file (django.core.files.images.ImageFile) – source file
Returns:transformed file
Return type:django.core.files.File

Converts a the file returned by django.db.models.fields.ImageField to a PIL image.

Parameters:django_file (django.db.models.fields.files.FieldFile) – django file
Return type:PIL.Image.Image

Gets a PIL image ready to be able to be saved using

It converts the mode first to RGB or L, so that it can then save it as a JPEG. It will save it as a progressive JPEG with a quality of IMAGE_QUALITY.

Parameters:pil_image (PIL.Image.Image) – original image
Returns:transformed image
Return type:django.core.files.base.ContentFile

Returns the transformed version of the PIL.Image.Image Do some logic on PIL.Image.Image.

Must subclass method to provide transformation logic.

Parameters:pil_image (PIL.Image.Image) – original image
Returns:transformed image
Return type:PIL.Image.Image
class simpleimages.transforms.Scale(width=None, height=None)[source]

Bases: simpleimages.transforms.BasePILTransform

Scales down an image to max height and/or width. If the original image is smaller than both/either specified dimensions than it will be left unchanged.

__init__(width=None, height=None)[source]

Initialize this class with a max height and/or width (in pixels).

  • height (int or float) – max height of scaled image
  • width (int or float) – max width of scaled image

Uses PIL.Image.Image.transform() to scale down the image.

Based on this stackoverflow discussions, uses PIL.Image.ANTIALIAS