Skip to main content

Extremly fast, (mostly) lossless JPEG transformations

Project description

Build status

jpegtran-cffi is a Python package for fast JPEG transformations. Compared to other, more general purpose image processing libraries like wand-py or PIL/Pillow, transformations are generally more than twice as fast (see Benchmarks). In addition, all operations except for scaling are lossless, since the image is not being re-compressed in the process. This is due to the fact that all transformation operations work directly with the JPEG data.

This is achieved by using multiple C routines from the Enlightenment project’s epeg library (for scaling) and the turbojpeg library from the libjpeg-turbo project (for all other operations). These routines are called from Python through the CFFI module, i.e. no external processes are launched.

The package also includes rudimentary support for getting and setting the EXIF orientation tag, automatically transforming the image according to it and obtaining the JFIF thumbnail image.

jpegtran-cffi was developed as part of a web interface for the spreads project, where a large number of images from digital cameras had to be prepared for display by a Raspberry Pi. With the Pi’s rather slow ARMv6 processor, both Wand and PIL were too slow to be usable.

Requirements

  • CPython >=2.7 or >=3.5 or PyPy

  • cffi >= 1.0

  • libturbojpeg with headers

Installation

$ pip install jpegtran-cffi

Usage

from jpegtran import JPEGImage

img = JPEGImage('image.jpg')

# JPEGImage can also be initialized from a bytestring
blob = requests.get("http://example.com/image.jpg").content
from_blob = JPEGImage(blob=blob)

# Reading various image parameters
print img.width, img.height  # "640 480"
print img.exif_orientation  # "1" (= "normal")

# If present, the JFIF thumbnail can be obtained as a bytestring
thumb = img.exif_thumbnail

# Transforming the image
img.downscale(320, 240).save('scaled.jpg')
img.rotate(90).save('rotated.jpg')
img.crop(0, 0, 100, 100).save('cropped.jpg')

# Transformations can be chained
data = (img.downscale(320, 240)
            .rotate(90)
            .flip('horizontal')
            .as_blob())

# jpegtran can transform the image automatically according to the EXIF
# orientation tag
photo = JPEGImage(blob=requests.get("http://example.com/photo.jpg").content)
print photo.exif_orientation  # "6" (= 270°)
print photo.width, photo.height # "4320 3240"
corrected = photo.exif_autotransform()
print corrected.exif_orientation  # "1" (= "normal")
print corrected.width, corrected.height  # "3240 4320"

For more details, refer to the API Reference.

Benchmarks

All operations were done on a 3.4GHz i7-3770 with 16GiB of RAM and a 7200rpm HDD with the following 2560x1920 8bit RGB JPEG:

http://upload.wikimedia.org/wikipedia/commons/8/82/Mandel_zoom_05_tail_part.jpg

https://jpegtran-cffi.readthedocs.io/en/latest/_images/benchmark.png

Both wand-py and PIL were run with the fastest scaling algorithm available, for wand-py this meant using Image.sample instead of Image.resize and for PIL the nearest-neighbour filter was used for the Image.resize call.

License

The MIT License (MIT)

Copyright (c) 2014 Johannes Baiter <johannes.baiter@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

jpegtran_cffi_wheels-0.5.3.dev0-cp311-cp311-win_amd64.whl (617.9 kB view details)

Uploaded CPython 3.11 Windows x86-64

jpegtran_cffi_wheels-0.5.3.dev0-cp311-cp311-win32.whl (551.5 kB view details)

Uploaded CPython 3.11 Windows x86

jpegtran_cffi_wheels-0.5.3.dev0-cp311-cp311-musllinux_1_1_x86_64.whl (719.3 kB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

jpegtran_cffi_wheels-0.5.3.dev0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (794.7 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

jpegtran_cffi_wheels-0.5.3.dev0-cp310-cp310-win_amd64.whl (617.9 kB view details)

Uploaded CPython 3.10 Windows x86-64

jpegtran_cffi_wheels-0.5.3.dev0-cp310-cp310-win32.whl (551.5 kB view details)

Uploaded CPython 3.10 Windows x86

jpegtran_cffi_wheels-0.5.3.dev0-cp310-cp310-musllinux_1_1_x86_64.whl (719.2 kB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

jpegtran_cffi_wheels-0.5.3.dev0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (794.7 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

jpegtran_cffi_wheels-0.5.3.dev0-cp39-cp39-win_amd64.whl (618.6 kB view details)

Uploaded CPython 3.9 Windows x86-64

jpegtran_cffi_wheels-0.5.3.dev0-cp39-cp39-win32.whl (552.2 kB view details)

Uploaded CPython 3.9 Windows x86

jpegtran_cffi_wheels-0.5.3.dev0-cp39-cp39-musllinux_1_1_x86_64.whl (719.3 kB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

jpegtran_cffi_wheels-0.5.3.dev0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (794.7 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

jpegtran_cffi_wheels-0.5.3.dev0-cp38-cp38-win_amd64.whl (618.6 kB view details)

Uploaded CPython 3.8 Windows x86-64

jpegtran_cffi_wheels-0.5.3.dev0-cp38-cp38-win32.whl (552.2 kB view details)

Uploaded CPython 3.8 Windows x86

jpegtran_cffi_wheels-0.5.3.dev0-cp38-cp38-musllinux_1_1_x86_64.whl (719.6 kB view details)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

jpegtran_cffi_wheels-0.5.3.dev0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (794.9 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

jpegtran_cffi_wheels-0.5.3.dev0-cp37-cp37m-win_amd64.whl (618.6 kB view details)

Uploaded CPython 3.7m Windows x86-64

jpegtran_cffi_wheels-0.5.3.dev0-cp37-cp37m-win32.whl (552.2 kB view details)

Uploaded CPython 3.7m Windows x86

jpegtran_cffi_wheels-0.5.3.dev0-cp37-cp37m-musllinux_1_1_x86_64.whl (719.0 kB view details)

Uploaded CPython 3.7m musllinux: musl 1.1+ x86-64

jpegtran_cffi_wheels-0.5.3.dev0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (794.4 kB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

File details

Details for the file jpegtran_cffi_wheels-0.5.3.dev0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for jpegtran_cffi_wheels-0.5.3.dev0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 69ff91595c0aa81bf64dbc4b145e5f128001de8aa92f3efbeecf612e81ed937e
MD5 b8412afc4d1ac01353aa4e245f6b01c5
BLAKE2b-256 7f61651addd03e17de775099d338e5d8055077cc1b476020fbf00334bd9a3602

See more details on using hashes here.

File details

Details for the file jpegtran_cffi_wheels-0.5.3.dev0-cp311-cp311-win32.whl.

File metadata

File hashes

Hashes for jpegtran_cffi_wheels-0.5.3.dev0-cp311-cp311-win32.whl
Algorithm Hash digest
SHA256 41bb3c0edd4b8768c0586b874ab78384ef9d08a9372fb50e03e88f2a2298649a
MD5 4349f9c96f7f88761eff20d139fe40a2
BLAKE2b-256 77d5b7aecde6210116868a7ef71b9baf28ff36a2e1903115552c04d5535efb1e

See more details on using hashes here.

File details

Details for the file jpegtran_cffi_wheels-0.5.3.dev0-cp311-cp311-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for jpegtran_cffi_wheels-0.5.3.dev0-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 72e11a9e1c7438581037d43014d47050d286ba8b711fba7bc4643f24443f1c70
MD5 9a56112dfb39c84d6ffa27a4d2379787
BLAKE2b-256 672bae2db7025d9010567296bd4b98d20de6efd4e81334dc6969e5504654ff19

See more details on using hashes here.

File details

Details for the file jpegtran_cffi_wheels-0.5.3.dev0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for jpegtran_cffi_wheels-0.5.3.dev0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 33a57387039e9f8b4d54384b05eeb7ff6c0ddf850d35846394aea13bcb52216c
MD5 01f7ec797f77b5fb5aecb8a4b4e4efcb
BLAKE2b-256 a907078f1fbc89c458a1dec42093d83d6a2b0d9c8cdc29fb7b2f9236edca8668

See more details on using hashes here.

File details

Details for the file jpegtran_cffi_wheels-0.5.3.dev0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for jpegtran_cffi_wheels-0.5.3.dev0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 34c016475431505cbcea9a136de21c6e79c5ea46173becf294c3fc42c37892c9
MD5 2b66ca959e7020e1c5dcfc84ff0eed84
BLAKE2b-256 b0b1437822a3a138ce5dc37823516b7235ae8a4d8ce1428a18e37db27f66ad8d

See more details on using hashes here.

File details

Details for the file jpegtran_cffi_wheels-0.5.3.dev0-cp310-cp310-win32.whl.

File metadata

File hashes

Hashes for jpegtran_cffi_wheels-0.5.3.dev0-cp310-cp310-win32.whl
Algorithm Hash digest
SHA256 add5425b6436e09d1b831f962a7c318ced7841d4a5a9c8fd843ba78b4364bf91
MD5 eee7de6fc41c89a51274b301b610c376
BLAKE2b-256 65769439b0ff2d000972c3bbcdead57124aaa713dc8f9ec59bd05795f9e65b2a

See more details on using hashes here.

File details

Details for the file jpegtran_cffi_wheels-0.5.3.dev0-cp310-cp310-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for jpegtran_cffi_wheels-0.5.3.dev0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 17e9781c04fd386b347452d83a1749b124468c76d9290bc3936336d680e10c40
MD5 5b56b311162d91316f4b68ffddf6b5f0
BLAKE2b-256 c406f4a50060f0c4062c6c437a4ed06728a8e5d37450bd3b17a4969bdbe4657f

See more details on using hashes here.

File details

Details for the file jpegtran_cffi_wheels-0.5.3.dev0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for jpegtran_cffi_wheels-0.5.3.dev0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e054470ab72d80869794dde8a2283aa09023053fb4ec4472078a83300ded93e1
MD5 bc43e48f73cc13257022b5a12cdea308
BLAKE2b-256 73aa6c9ea1f99651e52b0f51863281d67f1ad35abe2fc8e14a84a9daab76be3c

See more details on using hashes here.

File details

Details for the file jpegtran_cffi_wheels-0.5.3.dev0-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for jpegtran_cffi_wheels-0.5.3.dev0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 deed127d7bb9135eadc4d6389a89427d317b04de3344028b8a77ab9e73153283
MD5 e407f82d4534defb85069efcebfd979c
BLAKE2b-256 5b7a873650fe1c1458a05ddaedb8dca88fa63f56a2ba10ba9371e0413b90b051

See more details on using hashes here.

File details

Details for the file jpegtran_cffi_wheels-0.5.3.dev0-cp39-cp39-win32.whl.

File metadata

File hashes

Hashes for jpegtran_cffi_wheels-0.5.3.dev0-cp39-cp39-win32.whl
Algorithm Hash digest
SHA256 ff0ce3a266f66ab9a819a49c8b30ae5c39dfcaf40abd7e61440d386e24f26cbe
MD5 46b905163f4b4197184cfa37d08d8e04
BLAKE2b-256 5c304ca3c43614bee9480fab68b948abe56035c62f4760f8c20762368593fd75

See more details on using hashes here.

File details

Details for the file jpegtran_cffi_wheels-0.5.3.dev0-cp39-cp39-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for jpegtran_cffi_wheels-0.5.3.dev0-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 e9fb7f33687b534c5fa426f3725fdd98248e50b26d2cbe2d5ee4e8dcfc6f4552
MD5 195c39a6f722089b688db55bf9f4c359
BLAKE2b-256 996684a21e87efb8e823845200e5fd4a55f3543e4fa0bd19de53d74b3ac5b5a2

See more details on using hashes here.

File details

Details for the file jpegtran_cffi_wheels-0.5.3.dev0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for jpegtran_cffi_wheels-0.5.3.dev0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 362494f617dba7b8837dc37bbe7ad83111f3252e54e2f45e9c6c5fca0b99d0e7
MD5 4a4e797fc70f642ab0b923f26613a1f1
BLAKE2b-256 3f6bbf742a3c3b6b879f06d85da17a4c1ef71d60d9fa34fad522c7e91e4ab27c

See more details on using hashes here.

File details

Details for the file jpegtran_cffi_wheels-0.5.3.dev0-cp38-cp38-win_amd64.whl.

File metadata

File hashes

Hashes for jpegtran_cffi_wheels-0.5.3.dev0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 6f7ddbe6d3dd8ba20760eb8880bcd4b0a1453f3efdec67e8aa7c37af9d43d789
MD5 e134e01bc27c5da520fbbd7765bc1275
BLAKE2b-256 43ca058433da09b260b7ffa09cfbdee4b3bd27377c1db14974464761ddef837e

See more details on using hashes here.

File details

Details for the file jpegtran_cffi_wheels-0.5.3.dev0-cp38-cp38-win32.whl.

File metadata

File hashes

Hashes for jpegtran_cffi_wheels-0.5.3.dev0-cp38-cp38-win32.whl
Algorithm Hash digest
SHA256 de0939f290994f917793029630ba9cfa985b51f5c84f7de7285d9599fa4eafc8
MD5 3d883729343e96f7026dacf274a8639c
BLAKE2b-256 538bcc615a4c1799b1b3058f2c74cda6ce413c42c8eb96f260eeec56d91ec588

See more details on using hashes here.

File details

Details for the file jpegtran_cffi_wheels-0.5.3.dev0-cp38-cp38-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for jpegtran_cffi_wheels-0.5.3.dev0-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 4c3cbb40b613023b270cd08b394683bad2208cfc6fc420ac0d85e190f068ed34
MD5 2d9ccfe78d301023d79bcc23cb782b75
BLAKE2b-256 e175bc9f47d2bc7954f5593f76805948ce5f2db74709958591729affe84bd89e

See more details on using hashes here.

File details

Details for the file jpegtran_cffi_wheels-0.5.3.dev0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for jpegtran_cffi_wheels-0.5.3.dev0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 71a564be29d390e014f67742c42a489eb4124715f79a77d05e1d711eba772e1a
MD5 dfb7b9e270fa1ccb6dce8ccee28ec701
BLAKE2b-256 acc7bd7b0fa50e030179a2620b36fa06358c08c1eac5b361fa48af5a782aa2ba

See more details on using hashes here.

File details

Details for the file jpegtran_cffi_wheels-0.5.3.dev0-cp37-cp37m-win_amd64.whl.

File metadata

File hashes

Hashes for jpegtran_cffi_wheels-0.5.3.dev0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 cc85e09399711bfa51fc8709122461fbb40ee739af63bf59bd3c89ae5817626c
MD5 844de8e74766620c0cbc2e78ba882845
BLAKE2b-256 f77cd809e363414cda93b7bfe0c9d6273b8e8ea00e717a8eba4d143f6e1a8aa4

See more details on using hashes here.

File details

Details for the file jpegtran_cffi_wheels-0.5.3.dev0-cp37-cp37m-win32.whl.

File metadata

File hashes

Hashes for jpegtran_cffi_wheels-0.5.3.dev0-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 a3f548d9350351a5ef9e42aa726532341481d6760c4244ddd3cb64a1db0acfea
MD5 2a6a1e2a221510f6d65f006dd4b6930d
BLAKE2b-256 52b14f9af2ba2b5fb65195df52a70db7d74ab9b9fe84ccbf73cf927d62c277f5

See more details on using hashes here.

File details

Details for the file jpegtran_cffi_wheels-0.5.3.dev0-cp37-cp37m-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for jpegtran_cffi_wheels-0.5.3.dev0-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 c43b4be9dd17c38067ccc452cb6a9b41af9ee15cde077ae15aebd0ad24cdc97e
MD5 bec73898897fc263e04ffb43cd55acbc
BLAKE2b-256 7a1c9a2d93db956b0c646ec45145c13d077bc98772263609f755c90f6616c8e4

See more details on using hashes here.

File details

Details for the file jpegtran_cffi_wheels-0.5.3.dev0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for jpegtran_cffi_wheels-0.5.3.dev0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7277edf5c6b4b6cb23cae3fbc88e1d37089dc700a1d7a9daabdfd98e50ed1035
MD5 ada4db40c59306f0753af9fa410a3670
BLAKE2b-256 54a8826f3d74cceade99640d7e307de90c0a104da2d8138afea683355cb9b0d7

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