High-level image processing wrapper for libvips
Project description
ImageProcessing 🥚
Provides higher-level image processing helpers that are commonly needed when handling image uploads.
This package process images with the libvips library. Libvips is a library that can process images very rapidly (often multiple times faster than ImageMagick).
Requirements
You need to install first the libvips
library.
- In a MacOS terminal (using Homebrew) run:
brew install vips
- In a Debian/Ubuntu terminal run:
sudo apt install libvips-tools
Installation
Install this library with pip, or add it to your requirements/dependencies:
pip install image-processing-egg
Usage
Processing is performed through the ImageProcessing
class that
uses a chainable API for defining the processing pipeline:
from image_processing import ImageProcessing
processed = (
ImageProcessing(source_path)
.resize_to_limit(400, 400)
.convert("png")
.save()
)
processed #=> /temp/.../20180316-18446-1j247h6.png>
This allows easy branching when generating multiple derivates:
from image_processing import ImageProcessing
pipeline = ImageProcessing(source_path).convert("png")
large = pipeline.resize_to_limit(800, 800).save()
medium = pipeline.resize_to_limit(500, 500).save()
small = pipeline.resize_to_limit(300, 300).save()
The processing is executed with save()
.
processed = ImageProcessing(source_path) \
.convert("png") \
.resize_to_limit(400, 400) \
.save()
You can inspect the pipeline options at any point before executing it:
pipeline = ImageProcessing(source_path) \
.loader(page=1) \
.convert("png") \
.resize_to_limit(400, 400) \
.strip()
pipeline.options
# => {
# 'source': '/path/to/source.jpg',
# 'loader': {'page': 1},
# 'saver': {},
# 'format': 'png',
# 'operations': [
# ['resize_to_limit', [400, 400], {}],
# ['strip', [], {}],
# ]
# }
The source object needs to be a string or a Path
.
Note that the processed file is always saved to a new location,
in-place processing is not supported.
ImageProcessing("source.jpg")
ImageProcessing(Path("source.jpg"))
You can define the source at any time using source()
ImageProcessing().source("source.jpg")
ImageProcessing().source(Path("source.jpg"))
When save()
is called without options, the result of processing is a temp file. You can save the processing result to a specific location by passing a destination
, as a string or a Path, to save()
.
pipeline = ImageProcessing(source_path)
pipeline.save() #=> tempfile
pipeline.save("/path/to/destination")
Credits
This library is a port to Python of the Ruby image_processing gem.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file image-processing-egg-0.3.tar.gz
.
File metadata
- Download URL: image-processing-egg-0.3.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87da9da97d05f993443be8c74def26a3823ceb80fdb4b492373348da466ff563 |
|
MD5 | 0feefcc0d1ce8105578aaeaead315cbd |
|
BLAKE2b-256 | 65469617bc6b83b2eb7aa294c460daa0d34d3469ca6acbd8f786b40207977ff8 |
File details
Details for the file image_processing_egg-0.3-py3-none-any.whl
.
File metadata
- Download URL: image_processing_egg-0.3-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a00c119c0638243d1acfa91d1469dba02194f88eae6668a5a3fdebb0344ee0b8 |
|
MD5 | 8f81bb8f932028fedbe6c2958d374bfb |
|
BLAKE2b-256 | 25cfe41396cf0193beabfd367cb2824eebaa9bf91e8f7ccf11b7cbe33aa4a5a4 |