Skip to main content

Transparent image transformation system

Project description

https://travis-ci.org/jespino/django-tint.png?branch=master https://coveralls.io/repos/jespino/django-tint/badge.png?branch=master https://pypip.in/v/django-tint/badge.png https://pypip.in/d/django-tint/badge.png

Usage

You must define your transformation in your TINT_TRANSFORMATIONS settings variable.

You set your images on your models puting a ForeignKey to tint.models.Image.

Then you put your images in your templates using the at_transformation filter. Example:

{% load tint %}

<img src="{{ mymodel.my_image_field|at_transformation:"my-transformation-definition" }}" />

If you use django-jinja you only have to use the image_at_transformation function. Example:

<img src="{{ image_at_transformation(mymodel.my_image_field, "my-transformation-definition") }}" />

Default ImageProc Actions

Django-tint default Image Processor comes with some actions, here you have the list:

Action

Description

Params

crop

Crop an image to a width and height.

height, width, align, valign

scale

Scale an image to a width and height (deforming it).

height, width

fit

Scale an image to a width and height and crop the overflow.

height, width, align, valign

watermark

Paste a watermark on a image.

watermark_image, opacity

grayscale

Convert the image to grayscale.

flip

Flip the image vertically.

mirror

Flip the image horizontally.

equalize

Equalize the image histogram.

autocontrast

Maximize (normalize) image contrast.

cutoff

invert

Invert the image colors.

Configuration

In Django-tint you can define your ImageProc class (normally will be a subclass of the DefaultImageProc) to add your own image transformations. You can use it configuring the TINT_IMAGE_PROCESSOR settings variable. Example:

TINT_IMAGE_PROCESSOR = 'myapp.my_image_processor_module.MyImageProcessorClass'

If the variable is not defined the DefaultImageProc is used.

Then you can configure your transformations as a dictionary. The name of the transformation is the key, and the value is a list of “actions”. An action is a dictionary with one key ‘action’ with the name of the action, and the other keys the parameters to use in this action. Example:

TINT_TRANSFORMATIONS = {
  'example1': [
      {
          "action": 'fit',
          "width": 1024,
          "height": 768,
          "align": 'center',
          "valign": 'middle',
      },
      {
          "action": 'watermark',
          "image": 'example.watermark.png',
          "opacity": 0.5,
      },
  ],
  'example2': [
      {
          "action": 'fit',
          "width": 800,
          "height": 600,
          "align": 'center',
          "valign": 'middle',
      },
      {
          "action": 'watermark',
          "image": 'example.watermark.png',
          "opacity": 0.5,
      },
  ]
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-tint-0.0.4.tar.gz (8.5 kB view details)

Uploaded Source

File details

Details for the file django-tint-0.0.4.tar.gz.

File metadata

File hashes

Hashes for django-tint-0.0.4.tar.gz
Algorithm Hash digest
SHA256 4392439b6bb3805e2e69556094bad5ac750225f8596a16ede5d0f653c507aa07
MD5 e1cc496e8b1cd8319ca54d5036a657e8
BLAKE2b-256 f0e23c81843e459a4ee35e677ac5bd88d7e574f88ee5741af356e3a3f99579ba

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page