Python envelope for the popular C library libjpeg for handling JPEG files.
Project description
jpeglib
Python envelope for the popular C library libjpeg for handling JPEG files.
libjpeg offers full control over compression and decompression and exposes DCT coefficients and quantization tables.
Installation
Simply install the package with pip3
pip install jpeglib
Usage
Import the library in Python 3
import jpeglib
To install the dev version with all the libjpeg versions inside, type
pip uninstall jpeglib
pip install -U --no-cache-dir git+https://www.github.com/martinbenes1996/jpeglib.git@versions
:warning: Branch versions is dev so it is less stable and takes longer to install than the package.
DCT
Get discrete cosine transform (DCT) coefficients and quantization matrices as numpy array
im = jpeglib.read_dct("input.jpeg")
im.Y; im.Cb; im.Cr; im.qt
You get luminance DCT, chrominance DCT and quantization tables.
Write the DCT coefficients back to a file with
im.write_dct("output.jpeg")
Pixel data
Decompress the input.jpeg
into spatial representation in numpy array with
im = jpeglib.read_spatial("input.jpeg")
im.spatial
You can specify parameters such as output color space, DCT method, dithering, etc.
Write spatial representation in numpy arrray back to file with
im.write_spatial("output.jpeg")
You can specify input color space, DCT method, sampling factor, output quality, smoothing factor etc.
You can find all the details in the documentation.
libjpeg version
It is possible to choose, which version of libjpeg should be used.
jpeglib.version.set('6b')
Currently jpeglib
supports all versions of libjpeg from 6b to 9e, libjpeg-turbo 2.1.0 and mozjpeg 4.0.3.
Their source codes is baked inside the package and thus distributed with it, avoiding external dependency.
Get currently used libjpeg version by
version = jpeglib.version.get()
Credits
Developed by Martin Benes.
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.