transforms Module¶
-
class
simpleimages.transforms.BasePILTransform[source]¶ Bases:
objectBase transform object that provides helper methods to transform
django.core.files.images.ImageFileusingPIL.Must subclass and override
transform_pil_image().-
__call__(original_django_file)[source]¶ Returns the transformed version of
PIL.Image.ImageUses
transform_pil_image()to transform thePIL.Image.Image.Parameters: original_django_file ( django.core.files.images.ImageFile) – source fileReturns: transformed file Return type: django.core.files.File
-
django_file_to_pil_image(django_file)[source]¶ Converts a the file returned by
django.db.models.fields.ImageFieldto a PIL image.Parameters: django_file ( django.db.models.fields.files.FieldFile) – django fileReturn type: PIL.Image.Image
-
pil_image_to_django_file(pil_image)[source]¶ Gets a PIL image ready to be able to be saved using
django.db.models.fields.files.FieldFile.save()It converts the mode first to
RGBorL, so that it can then save it as aJPEG. It will save it as a progressiveJPEGwith a quality ofIMAGE_QUALITY.Parameters: pil_image ( PIL.Image.Image) – original imageReturns: transformed image Return type: django.core.files.base.ContentFile
-
-
class
simpleimages.transforms.Scale(width=None, height=None)[source]¶ Bases:
simpleimages.transforms.BasePILTransformScales 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).
Parameters: - height (int or float) – max height of scaled image
- width (int or float) – max width of scaled image
-
transform_pil_image(pil_image)[source]¶ Uses
PIL.Image.Image.transform()to scale down the image.Based on this stackoverflow discussions, uses
PIL.Image.ANTIALIAS
-