[](https://pypi.org/project/jpeglib/)
[](https://github.com/martinbenes1996/jpeglib/actions/workflows/on_commit.yml)
[](https://github.com/martinbenes1996/jpeglib/actions/workflows/on_release.yml)
[](https://jpeglib.readthedocs.io/)
[](https://pypi.org/project/jpeglib/)
[](https://github.com/martinbenes1996/jpeglib/stargazers)
[](https://github.com/martinbenes1996/jpeglib/graphs/contributors)
[](https://pypi.org/project/jpeglib/)
[](https://pypi.org/project/jpeglib/)
[](https://pypi.org/project/jpeglib/)
[](https://GitHub.com/martinbenes1996/jpeglib)
# 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
```bash
pip install jpeglib
```
or using the cloned repository
```bash
python setup.py install
```
> :warning: This will install `jpeglib` together with multiple versions of libjpeg, libjpeg-turbo and mozjpeg. For common architectures/OS we provide prebuilt wheels, but installing from source takes couple of minutes.
## Usage
Import the library in Python 3
```python
import jpeglib
```
### DCT
Get *discrete cosine transform* (DCT) coefficients and quantization matrices as numpy array
```python
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
```python
im.write_dct('output.jpeg')
```
### Pixel data
Decompress the `input.jpeg` into spatial representation in numpy array with
```python
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
```python
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](https://jpeglib.readthedocs.io/).
### libjpeg version
It is possible to choose, which version of libjpeg should be used.
```python
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
```python
version = jpeglib.version.get()
```
You can also set a libjpeg version for a scope only.
```python
jpeglib.version.set('6b')
im = jpeglib.read_spatial('image.jpeg') # using 6b
with jpeglib.version('9e'):
    im = jpeglib.read_spatial('image.jpeg') # using 9e
im = jpeglib.read_spatial('image.jpeg') # using 6b again
```
## Credits
Developed by [Martin Benes](https://github.com/martinbenes1996), University of Innsbruck, 2023.
            
         
        Raw data
        
            {
    "_id": null,
    "home_page": null,
    "name": "jpeglib",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "jpeglib, jpeg, jpg, libjpeg, compression, decompression, dct-coefficients, dct",
    "author": "Martin Bene\u0161",
    "author_email": "martinbenes1996@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/99/d7/5cadeb5790320923e205e5d682acdc63740bf40973d6bf15f7625a149eb8/jpeglib-1.0.2.tar.gz",
    "platform": null,
    "description": "[](https://pypi.org/project/jpeglib/)\n[](https://github.com/martinbenes1996/jpeglib/actions/workflows/on_commit.yml)\n[](https://github.com/martinbenes1996/jpeglib/actions/workflows/on_release.yml)\n[](https://jpeglib.readthedocs.io/)\n[](https://pypi.org/project/jpeglib/)\n[](https://github.com/martinbenes1996/jpeglib/stargazers)\n[](https://github.com/martinbenes1996/jpeglib/graphs/contributors)\n[](https://pypi.org/project/jpeglib/)\n[](https://pypi.org/project/jpeglib/)\n[](https://pypi.org/project/jpeglib/)\n[](https://GitHub.com/martinbenes1996/jpeglib)\n\n\n# jpeglib\n\nPython envelope for the popular C library libjpeg for handling JPEG files.\n\n*libjpeg* offers full control over compression and decompression and exposes DCT coefficients and quantization tables.\n\n## Installation\n\nSimply install the package with pip3\n\n\n```bash\npip install jpeglib\n```\n\nor using the cloned repository\n\n```bash\npython setup.py install\n```\n\n\n> :warning: This will install `jpeglib` together with multiple versions of libjpeg, libjpeg-turbo and mozjpeg. For common architectures/OS we provide prebuilt wheels, but installing from source takes couple of minutes.\n\n## Usage\n\nImport the library in Python 3\n\n```python\nimport jpeglib\n```\n\n### DCT\n\nGet *discrete cosine transform* (DCT) coefficients and quantization matrices as numpy array\n\n\n```python\nim = jpeglib.read_dct('input.jpeg')\nim.Y; im.Cb; im.Cr; im.qt\n```\n\nYou get luminance DCT, chrominance DCT and quantization tables.\n\nWrite the DCT coefficients back to a file with\n\n```python\nim.write_dct('output.jpeg')\n```\n\n### Pixel data\n\nDecompress the `input.jpeg` into spatial representation in numpy array with\n\n```python\nim = jpeglib.read_spatial('input.jpeg')\nim.spatial\n```\n\nYou can specify parameters such as output color space, DCT method, dithering, etc.\n\nWrite spatial representation in numpy arrray back to file with\n\n```python\nim.write_spatial('output.jpeg')\n```\n\nYou can specify input color space, DCT method, sampling factor, output quality, smoothing factor etc.\n\nYou can find all the details in the [documentation](https://jpeglib.readthedocs.io/).\n\n### libjpeg version\n\nIt is possible to choose, which version of libjpeg should be used.\n\n```python\njpeglib.version.set('6b')\n```\n\nCurrently `jpeglib` supports all versions of libjpeg from 6b to 9e, libjpeg-turbo 2.1.0 and mozjpeg 4.0.3.\nTheir source codes is baked inside the package and thus distributed with it, avoiding external dependency.\n\nGet currently used libjpeg version by\n\n```python\nversion = jpeglib.version.get()\n```\n\nYou can also set a libjpeg version for a scope only.\n\n```python\njpeglib.version.set('6b')\nim = jpeglib.read_spatial('image.jpeg') # using 6b\nwith jpeglib.version('9e'):\n    im = jpeglib.read_spatial('image.jpeg') # using 9e\nim = jpeglib.read_spatial('image.jpeg') # using 6b again\n```\n\n\n## Credits\n\nDeveloped by [Martin Benes](https://github.com/martinbenes1996), University of Innsbruck, 2023.\n\n",
    "bugtrack_url": null,
    "license": "MPL",
    "summary": "Python envelope for the popular C library libjpeg for handling JPEG files.",
    "version": "1.0.2",
    "project_urls": {
        "Documentation": "https://jpeglib.readthedocs.io/en/latest/",
        "Homepage": "https://pypi.org/project/jpeglib/",
        "Source": "https://github.com/martinbenes1996/jpeglib/"
    },
    "split_keywords": [
        "jpeglib",
        " jpeg",
        " jpg",
        " libjpeg",
        " compression",
        " decompression",
        " dct-coefficients",
        " dct"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "8fbd1e49f362ad057d237f27a5c4ef7bc35adc6e1928dab51dce3c565ad44d79",
                "md5": "a8cfb02e54cda76bb21baf2f0748f2a1",
                "sha256": "fa065e7239664facd4a4c8910968ca729c75ad811aa36b23e3b8dba14d3163b2"
            },
            "downloads": -1,
            "filename": "jpeglib-1.0.2-cp38-abi3-macosx_10_9_universal2.whl",
            "has_sig": false,
            "md5_digest": "a8cfb02e54cda76bb21baf2f0748f2a1",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": null,
            "size": 14453096,
            "upload_time": "2025-09-18T16:45:34",
            "upload_time_iso_8601": "2025-09-18T16:45:34.228117Z",
            "url": "https://files.pythonhosted.org/packages/8f/bd/1e49f362ad057d237f27a5c4ef7bc35adc6e1928dab51dce3c565ad44d79/jpeglib-1.0.2-cp38-abi3-macosx_10_9_universal2.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "3354d55db299c1572199847ef0707e1855e5a9f1d33abebc3148405c0760446d",
                "md5": "ffc7eb70b426687d93dd23d5fd2f9e96",
                "sha256": "7d160a4b0169e737fef2b3a8e58074ccb463425baf47725ff480818fd26dd4ff"
            },
            "downloads": -1,
            "filename": "jpeglib-1.0.2-cp38-abi3-macosx_10_9_x86_64.whl",
            "has_sig": false,
            "md5_digest": "ffc7eb70b426687d93dd23d5fd2f9e96",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": null,
            "size": 10690880,
            "upload_time": "2025-09-18T16:45:36",
            "upload_time_iso_8601": "2025-09-18T16:45:36.643457Z",
            "url": "https://files.pythonhosted.org/packages/33/54/d55db299c1572199847ef0707e1855e5a9f1d33abebc3148405c0760446d/jpeglib-1.0.2-cp38-abi3-macosx_10_9_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "d89e3e72638f1baf356edc683aad86c08034b5facdec912253be846dc0a60ccd",
                "md5": "641acc7a5c5a7d72953075b82ae6d9e9",
                "sha256": "1e97ed4c232d0a76b80d823ac8a72ce0e8c68003929de599c27423dfdacf5e96"
            },
            "downloads": -1,
            "filename": "jpeglib-1.0.2-cp38-abi3-macosx_11_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "641acc7a5c5a7d72953075b82ae6d9e9",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": null,
            "size": 10533860,
            "upload_time": "2025-09-18T16:45:38",
            "upload_time_iso_8601": "2025-09-18T16:45:38.651495Z",
            "url": "https://files.pythonhosted.org/packages/d8/9e/3e72638f1baf356edc683aad86c08034b5facdec912253be846dc0a60ccd/jpeglib-1.0.2-cp38-abi3-macosx_11_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "b4b5d3f0560b0b420aa5dccac348598217be8691e6cdd5a5269c805b85fe2e36",
                "md5": "3d6ce21e37cc46be0598f4b7e6f65892",
                "sha256": "e03cc447815efaf4cf0c22333ec207a9a8a0b9245bd0bafd15b30c2156ed1290"
            },
            "downloads": -1,
            "filename": "jpeglib-1.0.2-cp38-abi3-manylinux2010_i686.manylinux2014_i686.manylinux_2_12_i686.manylinux_2_17_i686.whl",
            "has_sig": false,
            "md5_digest": "3d6ce21e37cc46be0598f4b7e6f65892",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": null,
            "size": 22136496,
            "upload_time": "2025-09-18T16:45:40",
            "upload_time_iso_8601": "2025-09-18T16:45:40.962613Z",
            "url": "https://files.pythonhosted.org/packages/b4/b5/d3f0560b0b420aa5dccac348598217be8691e6cdd5a5269c805b85fe2e36/jpeglib-1.0.2-cp38-abi3-manylinux2010_i686.manylinux2014_i686.manylinux_2_12_i686.manylinux_2_17_i686.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "5af4d7b8c2d3934208963fd2388cf4316043cb6c8e8c7d55780b8d9a45b4f8b2",
                "md5": "95da920cecb71e4e5d0d2872f586562f",
                "sha256": "feef6e94c34cf8b27f7a888c1c8567c34686c32b1e6edb16716931e4ee18fece"
            },
            "downloads": -1,
            "filename": "jpeglib-1.0.2-cp38-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl",
            "has_sig": false,
            "md5_digest": "95da920cecb71e4e5d0d2872f586562f",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": null,
            "size": 22754356,
            "upload_time": "2025-09-18T16:45:43",
            "upload_time_iso_8601": "2025-09-18T16:45:43.727523Z",
            "url": "https://files.pythonhosted.org/packages/5a/f4/d7b8c2d3934208963fd2388cf4316043cb6c8e8c7d55780b8d9a45b4f8b2/jpeglib-1.0.2-cp38-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "a8c57d9d2e594b897b6c24fae5dcdd345bbcd3098f65e26943a12cb48a5d687d",
                "md5": "d39e88d837ba12c8c160697e19892e19",
                "sha256": "0b2d25da03f8710181367a4f1143215ad872c63b61dcad6665258b7ed051a5fb"
            },
            "downloads": -1,
            "filename": "jpeglib-1.0.2-cp38-abi3-win32.whl",
            "has_sig": false,
            "md5_digest": "d39e88d837ba12c8c160697e19892e19",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": null,
            "size": 9394019,
            "upload_time": "2025-09-18T16:45:45",
            "upload_time_iso_8601": "2025-09-18T16:45:45.942529Z",
            "url": "https://files.pythonhosted.org/packages/a8/c5/7d9d2e594b897b6c24fae5dcdd345bbcd3098f65e26943a12cb48a5d687d/jpeglib-1.0.2-cp38-abi3-win32.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "bb5b542403cdd0330733eeef421e4adc833d9862ed9b071f1607defe1f5cbe87",
                "md5": "ab0daac3410b5091ec5fe733c31c5bf5",
                "sha256": "abcc0be1c0b6adbff02b3b42805474fddbf6ac3182d619117a7e7c5cfa8f9bd2"
            },
            "downloads": -1,
            "filename": "jpeglib-1.0.2-cp38-abi3-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "ab0daac3410b5091ec5fe733c31c5bf5",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": null,
            "size": 9852148,
            "upload_time": "2025-09-18T16:45:47",
            "upload_time_iso_8601": "2025-09-18T16:45:47.928562Z",
            "url": "https://files.pythonhosted.org/packages/bb/5b/542403cdd0330733eeef421e4adc833d9862ed9b071f1607defe1f5cbe87/jpeglib-1.0.2-cp38-abi3-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "99d75cadeb5790320923e205e5d682acdc63740bf40973d6bf15f7625a149eb8",
                "md5": "de03938b05944593d59901e6cfd7b5b6",
                "sha256": "25eadd5497c94771c53deb6aa6646f0030ac24509fa9c3b89e984e11390bf3d9"
            },
            "downloads": -1,
            "filename": "jpeglib-1.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "de03938b05944593d59901e6cfd7b5b6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5671347,
            "upload_time": "2025-09-18T16:45:49",
            "upload_time_iso_8601": "2025-09-18T16:45:49.463820Z",
            "url": "https://files.pythonhosted.org/packages/99/d7/5cadeb5790320923e205e5d682acdc63740bf40973d6bf15f7625a149eb8/jpeglib-1.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-09-18 16:45:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "martinbenes1996",
    "github_project": "jpeglib",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "wheel",
            "specs": []
        },
        {
            "name": "numpy",
            "specs": []
        },
        {
            "name": "setuptools",
            "specs": []
        }
    ],
    "lcname": "jpeglib"
}