Skip to main content

Compress images in IPython/Jupyter notebooks

Project description

build-status-image pypi-version wheel

Overview

So you have included an image with IPython.display.Image() and the file size of your IPython Notebook got huge? No problem! This package will resize images in your notebook and compress them as PNG or JPEG. Images are only resized if they are above the specified width. 2048px and PNG compression is the default, which should give relative high quality images and normal sized notebooks. JPEG compression is nice if you serve the notebooks over the web (eg nbviewer) and prefer fast loading times.

Installation

Install using pip

pip install ipynbcompress

Example

From command line:

$ ipynb-compress notebook4.ipynb
notebook4.ipynb: 10 megabytes decrease
$ find . -name "*ipynb" -size +2M -exec ipynb-compress {} \;
./lab 03.21/automated scan.ipynb: warning: no compression - 0 bytes gained
./lab 03.21/automated scan.ipynb: compression less than 100k bytes - keeping original
./lab 03.21/trouble.ipynb: 9 megabytes decrease
...

In python:

>>> import os
>>> from ipynbcompress import compress
>>> filename = '/path/to/notebook.ipynb'
>>> out = '/path/to/compressed.ipynb'
>>> # original size
... os.stat(filename).st_size
11563736
>>> # return bytes saved
... compress(filename, output_filename=out, img_width=800, img_format='jpeg')
11451545
>>> compress(filename, output_filename=out, img_width=800, img_format='png')
11205762
>>> # defaults to img_width = 2048px and png compression
... compress(filename, output_filename=out)
11411377
>>> # overwrite existing notebook
... compress(filename)
11411377

API reference

API reference is at http://ipynbcompress.rtfd.org.

Development

Install dependencies and link development version of ipynbcompress to pip:

git clone https://github.com/arve0/ipynbcompress
cd ipynbcompress
pip install -r requirements.txt # install dependencies and ipynbcompress-package

Testing

pytest

Build documentation locally

To build the documentation:

pip install -r docs/requirements.txt
make docs

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

ipynbcompress-0.5.0.tar.gz (8.4 MB view details)

Uploaded Source

Built Distribution

ipynbcompress-0.5.0-py2.py3-none-any.whl (6.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file ipynbcompress-0.5.0.tar.gz.

File metadata

  • Download URL: ipynbcompress-0.5.0.tar.gz
  • Upload date:
  • Size: 8.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.17

File hashes

Hashes for ipynbcompress-0.5.0.tar.gz
Algorithm Hash digest
SHA256 b14de8f470a482c841e02186e7d1b5516211553ffa3646ac0f4c253094a5917d
MD5 3f2a902272c71c27d86ab98ab66a9bab
BLAKE2b-256 fc4c14fa91d45f713bcaf8a6e65e54f9eebee19bc4a465e1be12032b641787f8

See more details on using hashes here.

File details

Details for the file ipynbcompress-0.5.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for ipynbcompress-0.5.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 26b6b983aaf4f8c3fbff53431e23525bcae08d3edef5191a8b4d70238b6f5b7e
MD5 12b91ad2adb66c5f3d8b5ffea3d39bbb
BLAKE2b-256 1e96b0b36d0561e96b3eaa81484a423b471857830380d114ad57b62b6d058291

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