Skip to main content

To compress JPEG, PNG and GIF files losslessly in batch mode

Project description

Smally

Smally is a simple tool to compress JPEG, PNG and GIF files losslessly, by invoking the famous jpegtran, optipng and gifsicle tools, in batch mode, in-place and keep mtime unchanged. It is written in Python, but heavily rely on shell.

How to Compress

JPEG

  1. Using jpegtran to remove all metadata, create a baseline version and a progressive version.
  2. To compare among the original file, baseline and progressive files, choose the smallest one in size.
  3. Whenever possible, choose progressive version.

PNG

Calling optipng to compress PNG, in the most crazy -o7 -zm1-9 level.

GIF

Calling gifsicle to compress GIF, by using -O3 --color 256.

How to Install

# install tools on Fedora
$ sudo dnf install libjpeg-turbo-utils optipng gifsicle
# install tools on Ubuntu
$ sudo apt install libjpeg-turbo-progs optipng gifsicle
# install smally
$ pip install smally

How to Use

# inline help
$ python -m smally -h
# to compress a single file, if option is not presented,
# smally will use file command to get file type info.
$ python -m smally [-j|-p|-g] <pathname>
# to compress a directory
$ python -m smally -r -P<N> <pathname>
# to compress all png file in a directory
$ python -m smally -r -P<N> -p <pathname>

-r, recursively, it's a command line convention and normally you should use it when deal with a directory.

-P<N>, parallel process number, if it is missing, the logical cpu count number will be used.

APIs

4 APIs provided by smally:

# import
from smally import (jpegtran,
                    optipng,
                    gifsicle,
                    is_jpeg_progressive)
# signature
def jpegtran(pathname: str) -> tuple[int,int]: ...
def optipng(pathname: str) -> tuple[int,int]: ...
def gifsicle(pathname: str) -> tuple[int,int]: ...
def is_jpeg_progressive(pathname: str) -> bool: ...

The first int in returned tuple is the byte number saved. It could be zero, which means no save. The second int is the original file size.

Showcase

$ python -m smally -r smally/tpic -P4
# parallel process number:  4
smally/tpic/102.jpg -24157 -16.38% [p]
smally/tpic/302.gif -333056 -19.67%
smally/tpic/testpic/302.gif -333056 -19.67%
smally/tpic/testpic/102.jpg -24157 -16.38% [p]
smally/tpic/201.png -548 -26.37%
smally/tpic/testpic/201.png -548 -26.37%
smally/tpic/testpic/testpic/102.jpg -24157 -16.38% [p]
smally/tpic/testpic/testpic/302.gif -333056 -19.67%
smally/tpic/testpic/testpic/201.png -548 -26.37%

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

smally-0.53.tar.gz (1.8 MB view details)

Uploaded Source

Built Distribution

smally-0.53-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file smally-0.53.tar.gz.

File metadata

  • Download URL: smally-0.53.tar.gz
  • Upload date:
  • Size: 1.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.3

File hashes

Hashes for smally-0.53.tar.gz
Algorithm Hash digest
SHA256 0f4a1a2ba8bc4b985304c4ef9081bc2235e74d851141d49d8fb4b79852b471eb
MD5 085cc9fa001ab09e8856e12522837a6f
BLAKE2b-256 3ca7bb635e366058e294a91f5ce55c04c88ddd5c5108c3c7d81f67444d63ae64

See more details on using hashes here.

File details

Details for the file smally-0.53-py3-none-any.whl.

File metadata

  • Download URL: smally-0.53-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.3

File hashes

Hashes for smally-0.53-py3-none-any.whl
Algorithm Hash digest
SHA256 b9a1ec5224cdb2f702506343bbd49fcd0f7ed535294414b7448653cd8050b345
MD5 50c958ef504f66c4d50aa73030d3c4a2
BLAKE2b-256 89aa42666858bedba37188c9bb6f201686c41d124e9f0c468b5be18ecda47b71

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