Skip to main content

variations

A simple interface that allows processing of images.

PyPI Build Status Software license

Compatibility

  • python >= 3.7

Installation

  1. Run pip install variations

  2. (optional) If you want to use StackBlur

    pip install pillow-stackblur

  3. (optional) If you want to use Face Detection

    pip install face_recognition

Usage

from PIL import Image
from variations import processors
from variations.variation import Variation
from variations.utils import prepare_image

variation = Variation(
    size=(400, 0),
    max_height=800,
    clip=False,
    upscale=False,
    anchor=processors.Anchor.TOP_LEFT,
    jpeg=dict(
        quality=92,
    ),
    webp=dict(
        lossless=True,
        quality=90,
    ),
    postprocessors=[
        processors.ColorOverlay('#FF0000', overlay_opacity=0.25),
    ],
)

img = Image.open('source.jpg')
img = prepare_image(img, draft_size=variation.get_output_size(img.size))
new_img = variation.process(img)
dest_path = variation.replace_extension('dest.jpg')
variation.save(new_img, dest_path)

Options

Type Examples Description
size tuple
list
(640, 480)
(640, 0)
The canvas size of image. If you set the width or height to zero, the corresponding value will be automatically adjusted based on the aspect ratio
max_width int 640 It specifies the maximum width in pixels.This option have meaning only when corresponding value in size is zero
max_height int 480 It specifies the maximum height in pixels.This option have meaning only when corresponding value in size is zero
clip bool When set to True, the image can be cropped when filling the canvas.
upscale bool When set to True, the image can be upscaled when filling the canvas.
anchor str
tuple
list
'tr' (top right)
'c' (center)
(1, 1) (bottom right)
Defines the anchor point.
face_detection bool Use a face detection system to find anchor point. You must install facial recognition api to use this.
format str 'JPEG' 'png' 'WebP' Enforce output image format. Defaults to 'AUTO', which means keep input format.
preprocessors list [processors.Crop(width=200, height=120, x=50, y=50)] PilKit processors are invoked before the main processing stage
postprocessors list [processors.ColorOverlay('#0000FF', 0.10)] PilKit processors are invoked after the main processing stage

Additional options for specific formats

It is possible to pass additional options to Image.save() method.

Variation(
    # ...
    jpeg=dict(
        quality=80,
        progressive=True,
    ),
    webp=dict(
        autoconvert=False,
        quality=80,
    ),
    tiff=dict(
        compression='tiff_jpeg',
    )
)

Development and Testing

After cloning the Git repository, you should install this in a virtualenv and set up for development:

virtualenv .venv
source .venv/bin/activate
pip install -r ./requirements.txt
pre-commit install

Metadata

Release files for variations 0.3.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for variations 0.3.3
File Size Uploaded
variations-0.3.3.tar.gz 19.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for variations 0.3.3
File Interpreter ABI Platform
variations-0.3.3-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 35.1 kB

Release files / variations-0.3.3.tar.gz

Download URL variations-0.3.3.tar.gz
Size 19.4 kB
Tags Source
SHA-256 checksum
How to use checksums
0d5e0abf74b1ffca27afdbdf3595f9cb0b6bc0c70616c83d4a3235830d05af80
BLAKE2b-256 checksum
How to use checksums
6c10746e6cfccff1fa2a29140bb071f34241321d4800e733e909a0c4285f9400
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Release files / variations-0.3.3-py2.py3-none-any.whl

Download URL variations-0.3.3-py2.py3-none-any.whl
Size 15.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
b30b10e979bc232060953cf17efd8f9af11f7efae4523b81bfb1b77a7bc52697
BLAKE2b-256 checksum
How to use checksums
f99743d7d5ce691dd8194285f973529eeddd4659a8e581f6a432068b481910f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Release history Release notifications | RSS feed

This release

0.3.3 This release

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.17

2 release files

0.0.15

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page