utils Module

simpleimages.utils.perform_transformation(instance, field_names_to_transform=None)[source]

Transforms a model based on the fields specified in the transformed_fields attribute. This should map source image field names to dictionaries mapping destination field name to their transformations. For instance:

    'image': {
        'thumbnail': scale(width=10),

If field_names_to_transform is None, then it will transform all fields. Otherwise it will only transform from those fields specified in field_names_to_transform.

  • instance (instance of django.db.models.Model) – model instance to perform transformations on
  • field_names_to_transform (iterable of strings or None) – field names on model to perform transformations on
simpleimages.utils.transform_field(instance, source_field_name, destination_field_name, transformation)[source]

Does an image transformation on a instance. It will get the image from the source field attribute of the instnace, then call the transformation function with that instance, and finally save that transformed image into the destination field attribute of the instance.


If the source field is blank or the transformation returns a false value then the destination field image will be deleted, if it exists.


When the model instance is saved with the new transformed image, it uses the update_fields argument for save(), to tell the model to only update the destination field and, if set in the destination field, the height_field and width_field. This means that if the saving code for the model sets any other fields, in the saving field process, it will not save those fields to the database. This would only happen if you introduce custom logic to the saving process of destination field, like the dimension fields do, that updates another field on that module. In that case, when the model is saved for the transformation, that other field will not be saved to the database.

  • instance (instance of django.db.models.Model) – model instance to perform transformations on
  • source_field_name (string) – field name on model to find source image
  • destination_field_name (string) – field name on model save transformed image to
  • transformation (function) – function, such as scale(), that takes an image files and returns a transformed image