Skip to main content

Optimize JPEGs losslessly using MozJPEG

Project description

Github Discord PYPI Version Build Status Black License

This library optimizes JPEGs losslessly using MozJPEG.

To reduce the file sizes,

  • the Huffman table of the JPEGs is optimized,

  • the baseline JPEGs are converted to progressive JPEGs,

  • and any metadata and ICC profiles are removed.

The JPEGs optimized with this library are identical to what you get using the jpegtran tool from MozJPEG with the -optimize, -progressive and -copy none options.

Usage

import mozjpeg_lossless_optimization

with open("./image.jpg", "rb") as input_jpeg_file:
    input_jpeg_bytes = input_jpeg_file.read()

output_jpeg_bytes = mozjpeg_lossless_optimization.optimize(input_jpeg_bytes)

with open("./out.jpg", "wb") as output_jpeg_file:
    output_jpeg_file.write(output_jpeg_bytes)

Install

From Sources

To install MozJPEG Lossless Optimization, MozJPEG will be compiled, so you will need a C compilator and cmake. On Debian / Ubuntu you can install everything you need with the following command:

sudo apt install build-essential cmake python3 python3-dev python3-pip python3-setuptools

Once everything installed, clone this repository:

git clone https://github.com/wanadev/mozjpeg-lossless-optimization.git

Then navigate to the project’s folder:

cd mozjpeg-lossless-optimization

Retrieve submodules:

git submodule init
git submodule update

And finally build and install using the following command (as root on Linux):

python3 setup.py install

Hacking

Get the source and build C lib and module:

# Install system dependencies
sudo apt install build-essential cmake python3 python3-dev python3-pip python3-setuptools

# Get the sources
git clone https://github.com/wanadev/mozjpeg-lossless-optimization.git
cd mozjpeg-lossless-optimization
git submodule init
git submodule update

# Create and activate a Python virtualenv
python3 -m venv __env__
source __env__/bin/activate

# Install Python dependencies in the virtualenv
pip install cffi

# Build MozJPEG
# This will generate files in ./mozjpeg/build/ folder
python setup.py build

# Build the CFFI module "in-place"
# This will create the ./mozjpeg_lossless_optimization/_mozjpeg_opti.*.so file on Linux
python ./mozjpeg_lossless_optimization/mozjpeg_opti_build.py

Lint:

pip install nox
nox -s lint

Licenses

MozJPEG Lossless Optimization is licensed under the BSD 3 Clause license. See the LICENSE file for more information.

MozJPEG is covered by three compatible BSD-style open source licenses. See its license file for more information.

Changelog

  • v0.9.0: First public release

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

mozjpeg-lossless-optimization-0.9.0.tar.gz (1.0 MB view details)

Uploaded Source

Built Distributions

mozjpeg_lossless_optimization-0.9.0-cp39-cp39-win_amd64.whl (58.3 kB view details)

Uploaded CPython 3.9 Windows x86-64

mozjpeg_lossless_optimization-0.9.0-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (125.9 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

mozjpeg_lossless_optimization-0.9.0-cp39-cp39-manylinux_2_12_i686.manylinux2010_i686.whl (140.9 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.12+ i686

mozjpeg_lossless_optimization-0.9.0-cp39-cp39-macosx_10_14_x86_64.whl (74.1 kB view details)

Uploaded CPython 3.9 macOS 10.14+ x86-64

mozjpeg_lossless_optimization-0.9.0-cp38-cp38-win_amd64.whl (58.3 kB view details)

Uploaded CPython 3.8 Windows x86-64

mozjpeg_lossless_optimization-0.9.0-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (126.3 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

mozjpeg_lossless_optimization-0.9.0-cp38-cp38-manylinux_2_12_i686.manylinux2010_i686.whl (141.2 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ i686

mozjpeg_lossless_optimization-0.9.0-cp38-cp38-macosx_10_14_x86_64.whl (74.1 kB view details)

Uploaded CPython 3.8 macOS 10.14+ x86-64

mozjpeg_lossless_optimization-0.9.0-cp37-cp37m-win_amd64.whl (58.3 kB view details)

Uploaded CPython 3.7m Windows x86-64

mozjpeg_lossless_optimization-0.9.0-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (125.8 kB view details)

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

mozjpeg_lossless_optimization-0.9.0-cp37-cp37m-manylinux_2_12_i686.manylinux2010_i686.whl (140.8 kB view details)

Uploaded CPython 3.7m manylinux: glibc 2.12+ i686

mozjpeg_lossless_optimization-0.9.0-cp37-cp37m-macosx_10_14_x86_64.whl (74.1 kB view details)

Uploaded CPython 3.7m macOS 10.14+ x86-64

File details

Details for the file mozjpeg-lossless-optimization-0.9.0.tar.gz.

File metadata

  • Download URL: mozjpeg-lossless-optimization-0.9.0.tar.gz
  • Upload date:
  • Size: 1.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.5

File hashes

Hashes for mozjpeg-lossless-optimization-0.9.0.tar.gz
Algorithm Hash digest
SHA256 6e8cf9ea37b6df93897492f60720f4e6f5b11598717968dd73603b2357477b62
MD5 088854be7941bbbe5b3ee3e20034ba4f
BLAKE2b-256 e165d8c69e6c6305ec28d862e52c1ef6d116d0c416dc3b117070813b73a12614

See more details on using hashes here.

File details

Details for the file mozjpeg_lossless_optimization-0.9.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: mozjpeg_lossless_optimization-0.9.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 58.3 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for mozjpeg_lossless_optimization-0.9.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 d6882916e140f0570084831830beceb9a0df7d7efcf39868b53e8871d2aa8a90
MD5 4d2ce5034274eb659c23a7eeef352f0c
BLAKE2b-256 67d292ff8a15152c9794c4184abf94fc971fb615505ca96342e9f3f39018cead

See more details on using hashes here.

File details

Details for the file mozjpeg_lossless_optimization-0.9.0-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for mozjpeg_lossless_optimization-0.9.0-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 0b9d972ccdaf0123e297e5b590d3991fea26013cd9af500bd248148aaeefba89
MD5 cd2e9dc6965cedfd4f7e15741be1fc36
BLAKE2b-256 32ac387f9acf0fbbd004cb85d582d81690d41c85530af644bdd3eabf46d8c6fd

See more details on using hashes here.

File details

Details for the file mozjpeg_lossless_optimization-0.9.0-cp39-cp39-manylinux_2_12_i686.manylinux2010_i686.whl.

File metadata

File hashes

Hashes for mozjpeg_lossless_optimization-0.9.0-cp39-cp39-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm Hash digest
SHA256 ca641209c61fd17fa266e3ae1997912b38193298a10d86b2ba63886707b4db00
MD5 cbb5fc7708d4baa92c7c28baceaaea3a
BLAKE2b-256 3c3aa92d0aa1225d0d731926c05d3aa946c9fb5dcffd1e0ac49c3b13c1e9b4c1

See more details on using hashes here.

File details

Details for the file mozjpeg_lossless_optimization-0.9.0-cp39-cp39-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for mozjpeg_lossless_optimization-0.9.0-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 c3f7210b9143fbd20a6bc832d4ad2390771310c56519da44a5c8557bca15bc3c
MD5 200724e5602ebebdf078ceae3ad336be
BLAKE2b-256 e54d07f650c7db89d644da2b817e3d38277faea178cbc94cc81fc91ad8c7af00

See more details on using hashes here.

File details

Details for the file mozjpeg_lossless_optimization-0.9.0-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: mozjpeg_lossless_optimization-0.9.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 58.3 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for mozjpeg_lossless_optimization-0.9.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 9e1bd3c104dfb027b1d4bcf0c7d4e2ca9c6bfbb6b3b52d465d18c635aba0a0b0
MD5 aac008e131f1e4da6d8f1104955437fd
BLAKE2b-256 1d282dcd8cc21ef10d675c8b3c663b611649e862bdd4d407f8d52f72657645df

See more details on using hashes here.

File details

Details for the file mozjpeg_lossless_optimization-0.9.0-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for mozjpeg_lossless_optimization-0.9.0-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 1c1f37bd1b1fcf9c59eedac66a9c830eb72e72559ec09759bcfb879769a9ca5b
MD5 cea3c65c86fb32137a362ee3276771bd
BLAKE2b-256 91a74943512f886fae516db360fd3a5dbe918ce4f66ae0b266d6c9a957508994

See more details on using hashes here.

File details

Details for the file mozjpeg_lossless_optimization-0.9.0-cp38-cp38-manylinux_2_12_i686.manylinux2010_i686.whl.

File metadata

File hashes

Hashes for mozjpeg_lossless_optimization-0.9.0-cp38-cp38-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm Hash digest
SHA256 1873b704ef028b0628ecb0020203d59c6712b6273a7e60febe29a381aa472186
MD5 2f68521750f794346c97edcce12fff53
BLAKE2b-256 9108ece24f270a01fb1e1338c42ed754be5b9ab8d505860ea46cf675ab9a3e65

See more details on using hashes here.

File details

Details for the file mozjpeg_lossless_optimization-0.9.0-cp38-cp38-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for mozjpeg_lossless_optimization-0.9.0-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 ca589cb3135a6ff48303c1e6aa6855950c110072e06b64d84ea97b81f8b05dd6
MD5 d46a38cd4d6cd664505df621754f20e7
BLAKE2b-256 e9e33062b4c86a6fe9425bb203e55c45131a1f029656ec2be91685fbb0d95816

See more details on using hashes here.

File details

Details for the file mozjpeg_lossless_optimization-0.9.0-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: mozjpeg_lossless_optimization-0.9.0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 58.3 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for mozjpeg_lossless_optimization-0.9.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 9e479c694b2416a5d08b66a389f37fa0c36b2cdd364a2fe54ef78944619a107d
MD5 f38714373428dfddc37bbc30b488957c
BLAKE2b-256 d6d4fafecaf0ca6bb21f89605f652a289419d65d05c6e32e6c3178d7d63b8ba4

See more details on using hashes here.

File details

Details for the file mozjpeg_lossless_optimization-0.9.0-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for mozjpeg_lossless_optimization-0.9.0-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 bc3935ac575de8a33647e80e1c041e73af0490ac5a90f3039fddd41a0b5c5edd
MD5 1d180c7cf8f2b4f07cd81ba31ae231ca
BLAKE2b-256 54ac78a07d65f7f4a5387b597eef56a74974a19e591e6064fcf87089f9934378

See more details on using hashes here.

File details

Details for the file mozjpeg_lossless_optimization-0.9.0-cp37-cp37m-manylinux_2_12_i686.manylinux2010_i686.whl.

File metadata

File hashes

Hashes for mozjpeg_lossless_optimization-0.9.0-cp37-cp37m-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm Hash digest
SHA256 4cf33c9380894234adf6dbbb2a0e8fc377a2fa880abe089b38fa39579e6d6f6a
MD5 fb83ed31a5c36ba6b69550a181621950
BLAKE2b-256 e92419487d966044c4e349a2affdcfa4b6fd9f6b95475c6c0a701fcfe14623ca

See more details on using hashes here.

File details

Details for the file mozjpeg_lossless_optimization-0.9.0-cp37-cp37m-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for mozjpeg_lossless_optimization-0.9.0-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 771f6f701019509b311337ba9da53a7d49e5ab19e6fbe0830a9b3797b5593839
MD5 a3b02f7f4a56f9e3e287c0dfaddff035
BLAKE2b-256 5ca933d82b3d563c768f224855bee86e47f65de8e6339f140f1b5922051f9b00

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