Skip to main content

A multi format lossless image optimizer that uses external tools

Project description

picopt

A multi-format, recursive, multiprocessor aware, command line lossless image optimizer utility that uses external tools to do the optimizing.

Picopt depends on Python PIL to identify files and Python rarfile to open CBRs.

Picopt will optionally drop hidden timestamps at the root of your image directories to avoid reoptimizing images picopt has already optimized.

The actual image optimization is best accomplished by external programs.

Conversion Philosophy

Lossy Images

JPEG & Lossy WebP images are likely the best and most practical lossy image formats. Converting lossy images rarely makes sense and so picopt only optimizes them in their current format.

Lossless Images

Lossless WebP images are smaller than PNG, much smaller than GIF and, of course, a great deal smaller thein uncompressed bitmaps like BMP. As such the best practice is probably to convert all lossless images to WebP Lossless as now all major browsers support it. The only downside is that decoding WebP Lossless takes on average 50% more CPU than PNG.

Sequenced Images

Sequenced Images, like animated GIFs and WebP, most of the time, should be converted to a compressed video format like HEVC or VP9. There are several situations where this is impractical and so Animated WebP is now a good substitute.

Conversion

By default picopt does not convert images between formats. You must turn on conversion to PNG or WebP explicitly.

Formats

  • By default picopt will optimize GIF, JPEG, PNG and WEBP images.
  • Picopt can optionally optimize ZIP, ePub, and CBZ containers.
  • Picopt can be told to convert lossless images such as BPM, PPM, GIF, TIFF into PNG, and all of the mentioned lossless formats into WebP.
  • Picopt can convert Animated GIFs into Animated WebP files.
  • Picopt can convert Animated PNGs (APNG) into Animated WebP files, but does not optimize APNG as APNG.
  • Picopt can convert RAR files into Zipfiles and CBR files into CBZ files.

External Programs

Picopt will perform some minor optimization on most formats natively without using external programs, but this is not very good compared to the optimizations external programs can provide.

JPEG

To optimize JPEG images. Picopt needs one of mozjpeg or jpegtran on the path. in order of preference.

PNG

To optimize PNG images or convert other lossless formats to PNG picopt requires either optipng or pngout be on the path. Optipng provides the most advantage, but best results will be had by using pngout as well.

Animated GIF

Animated GIFs are optimized with gifsicle if it is available.

WebP

WebP lossless & lossy formats are optimized with cwebp.

EPub

EPub Books are zip files that often contain images and picopt unpacks and repacks this format natively. Images within the epub are handled by other programs. EPub optimization is not turned on by default. EPub contents are never converted to other formats because it would break internal references to them.

CBZ & CBR

Picopt uncompresses, optimizes and rezips comic book archive files. Be aware that CBR rar archives may only be rezipped into CBZs instead of CBR. Comic book archive optimization is not turned on by default to prevent surprises.

Install

System Dependencies

picopt requires several external system dependencies to run. We must install these first

macOS

brew install webp mozjpeg optipng jonof/kenutils/pngout gifsicle

ln -s $(brew --prefix)/opt/mozjpeg/bin/jpegtran /usr/local/bin/mozjpeg

Unfortunately hombrew's webp formula does not yet install the gif2webp tool that picopt uses for converting animated gifs to animated webps. You may manually download it and put it in your path at Google's WebP developer website

Debian / Ubuntu

apt-get install optipng gifsicle python-imaging webp

if you don't want to install mozjpeg using the instructions below then use jpegtran:

apt-get install libjpeg-progs

Redhat / Fedora

yum install optipng gifsicle python-imaging libwebp-tools

if you don't want to install mozjpeg using the instructions below then use jpegtran:

yum install libjpeg-progs

MozJPEG

mozjpeg offers better compression than libjpeg-progs jpegtran. It may or may not be packaged for your *nix, but even when it is, picopt requires that its separately compiled version of jpegtran be symlinked to 'mozjpeg' somewhere in the path.

Instructions for installing on macOS are given above. Some near recent binaries for Windows and Debian x86 can be found here. Most Linux distributions still require a more manual install as elucidated here on Casey Hoffer's blog

pngout

pngout is a useful compression to use after optipng. It is not packaged for linux, but you may find the latest binary version on JonoF's site. Picopt looks for the binary to be called pngout

Picopt python package

pip install picopt

Usage Examples

Optimize all JPEG files in a directory:

picopt *.jpg

Optimize all files and recurse directories:

picopt -r *

Optimize files, recurse directories, also optimize ePub & CBZ containers, convert lossless images into WEBP, convert CBR into CBZ.

picopt -rx EPUB,CBR,CBZ -c WEBP,CBZ *

Optimize files and recurse directories AND optimize comic book archives:

picopt -rx CBZ *

Optimize comic directory recursively. Convert CBRs to CBZ. Convert lossless images, including TIFF, to lossless WEBP. Do not follow symlinks. Set timestamps.

picopt -rStc CBZ,WEBP -x TIFF,CBR,CBZ /Volumes/Media/Comics

Optimize all files, but only JPEG format files:

picopt -f JPEG *

Optimize files and containers, but not JPEGS:

picopt -f GIF,PNG,WEBP,ZIP,CBZ,EPUB *

Optimize files, but not animated gifs:

picopt -f PNG,WEBP,ZIP,CBZ,EPUB *

Just list files picopt.py would try to optimize:

picopt -L *

Optimize pictures in my iPhoto library, but only after the last time I did this, skipping symlinks to avoid duplicate work. Also drop a timestamp file so I don't have to remember the last time I did this:

picopt -rSt -D '2013 June 1 14:00' 'Pictures/iPhoto Library'

Packages

Alternatives

imagemin looks to be an all in one cli and gui solution with bundled libraries, so no awkward dependencies. Imageoptim is an all-in-one OS X GUI image optimizer. Imageoptim command line usage is possible with an external program.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

picopt-3.2.0.tar.gz (2.5 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

picopt-3.2.0-py3-none-any.whl (30.7 kB view details)

Uploaded Python 3

File details

Details for the file picopt-3.2.0.tar.gz.

File metadata

  • Download URL: picopt-3.2.0.tar.gz
  • Upload date:
  • Size: 2.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.4 Linux/5.13.0-1023-aws

File hashes

Hashes for picopt-3.2.0.tar.gz
Algorithm Hash digest
SHA256 891d2383612f8687a6404c94d72e8bb91de64d5ef7da553f4b529efbef430c38
MD5 4837657fa6d80a150e5a9d161d835ff5
BLAKE2b-256 156b1314eb5309ee20d156d95508aa8bd10d224d8f2ed4bdcb43089b277abee7

See more details on using hashes here.

File details

Details for the file picopt-3.2.0-py3-none-any.whl.

File metadata

  • Download URL: picopt-3.2.0-py3-none-any.whl
  • Upload date:
  • Size: 30.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.4 Linux/5.13.0-1023-aws

File hashes

Hashes for picopt-3.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 272004e0ecb268476348cddf365df8924a9e4033cecbd1676c273961721de76f
MD5 13229caed5536cd8aff118a139011ac1
BLAKE2b-256 8cf69b9f1c507b6ab519bcb32dcf63dba22a7e52c9c93737d248091fb0cc7dbc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page