17 releases (10 breaking)

0.11.0-next.0 May 5, 2024
0.10.3 Jan 21, 2024
0.10.2 Dec 28, 2023
0.9.1 Oct 16, 2023
0.2.0 Mar 27, 2023

#83 in Images

Download history 4/week @ 2024-01-21 10/week @ 2024-02-04 22/week @ 2024-02-18 31/week @ 2024-02-25 211/week @ 2024-03-03 15/week @ 2024-03-10 1/week @ 2024-03-17 18/week @ 2024-03-31 11/week @ 2024-04-07 1/week @ 2024-04-14 8/week @ 2024-04-21 73/week @ 2024-05-05

83 downloads per month

MIT/Apache and maybe GPL-3.0-or-later

115KB
2.5K SLoC

Rimage

build status docs.rs version license

A powerful Rust image optimization CLI tool inspired by squoosh!.

Features

  • Modern codecs:
    • Rimage uses modern codecs optimized to produce tiny images
    • Under the hood uses zune_image crate that enhances performance
  • Optimization operations:
    • Rimage provides several image optimization operation
    • Resize - uses fast_image_resize crate that has incredible performance
    • Quantization - allowing to reduce image palette

Installation

You can download latest release from the releases tab.

If you're a Rust programmer, rimage can be installed with cargo.

cargo install rimage

Alternatively, one can use cargo binstall to install a rimage binary directly from GitHub:

cargo binstall rimage

Note

If you're a user who just want to use Rimage easily with a friendly GUI, Rimage_gui may be fit for you, it support both Chinese and English. Just select the version you need and download it to use.

Usage

Optimize images natively with best-in-class codecs

Usage: rimage [COMMAND]

Commands:
  avif      Encode images into AVIF format. (Small and Efficient)
  farbfeld  Encode images into Farbfeld format. (Bitmapped)
  jpeg      Encode images into JPEG format. (Progressive-able)
  jpeg_xl   Encode images into JpegXL format. (Big but Lossless)
  mozjpeg   Encode images into JPEG format using MozJpeg codec. (RECOMMENDED and Small)
  oxipng    Encode images into PNG format using OxiPNG codec. (Progressive-able)
  png       Encode images into PNG format.
  ppm       Encode images into PPM format. (Bitmapped)
  qoi       Encode images into QOI format. (Trendy and Small)
  webp      Encode images into WebP format. (Lossless-able)
  help      Print this message or the help of the given subcommand(s)

Options:
  -h, --help     Print help
  -V, --version  Print version

Basic optimization suitable for web

To optimize images with great defaults, you can simply call rimage <command>. For example:

rimage mozjpeg ./image.jpg

By default rimage will place output images right in place of precious images, resulting in overwrite if input and output has the same format. To change this behavior you can use this options:

# will place output images in `./output` directory, images may be overwritten if has the same name
rimage mozjpeg -d ./output ./image.jpg

# will rename all input files before processing with `@backup` suffix
rimage mozjpeg --backup ./image.jpg

# will place output images in ./output directory preserving folder structure
rimage mozjpeg -d ./output -r ./inner/image.jpg ./image.jpg

Preprocessing

Rimage has pipeline preprocessing options. Simple usage:

# will resize image to specified dimensions
rimage mozjpeg --resize 500x200 ./image.jpg

If you want to run preprocessing pipeline in specific order, you can do this:

# will quantize image with 80% quality, after run resize to 64x64 pixels using the Nearest filter.
rimage mozjpeg --quantization 80 --resize 64x64 --filter nearest ./image.jpg

# will resize image to 64x64 pixels using the Nearest filter, and after run quantization with 80% quality.
rimage mozjpeg --resize 64x64 --filter nearest --quantization 80 ./image.jpg

Note that some preprocessing option are order independent. For example filter option, will apply resize filter to all resize invocations. Same for dithering, applies to every quantization invocations.

Advanced options

If you want customize optimization you can provide additional options to encoders. For mozjpeg this options are valid:

Options:
  -q, --quality <NUM>         Quality, values 60-80 are recommended. [default: 75]
      --chroma_quality <NUM>  Separate chrome quality.
      --baseline              Set to use baseline encoding (by default is progressive).
      --no_optimize_coding    Set to make files larger for no reason.
      --smoothing <NUM>       Use MozJPEG's smoothing.
      --colorspace <COLOR>    Set color space of JPEG being written. [default: ycbcr] [possible values: ycbcr, grayscale, rgb]
      --multipass             Specifies whether multiple scans should be considered during trellis quantization.
      --subsample <PIX>       Sets chroma subsampling.
      --qtable <TABLE>        Use a specific quantization table. [default: NRobidoux] [possible values: AhumadaWatsonPeterson, AnnexK, Flat, KleinSilversteinCarney, MSSSIM, NRobidoux, PSNRHVS, PetersonAhumadaWatson, WatsonTaylorBorthwick]

For more info use rimage help <command>

For library usage check Docs.rs

List of supported Codecs

Image Codecs Decoder Encoder NOTE
avif libavif ravif Common features only, Static only
bmp zune-bmp X Input only
farbfeld zune-farbfeld zune-farbfeld
hdr zune-hdr zune-hdr
jpeg zune-jpeg mozjpeg or jpeg-encoder Multifunctional when use mozjpeg encoder
jpeg-xl jxl-oxide zune-jpegxl Lossless only
png zune-png oxipng or zune-png Static only, Multifunctional when use oxipng encoder
ppm zune-ppm zune-ppm
psd zune-psd X Input only
qoi zune-qoi zune-qoi
webp webp webp Static only

List of supported preprocessing options

  • Resize
  • Quantization
  • Alpha premultiply

Known bugs

  • Dir path end with \ may cause rimage crashes due to a cmd bug #72653.

Example:

This will crash:

rimage png "D:\example.jpg" -d "D:\desktop\" -s "suffix"

This will work as expected:

rimage png "D:\example.jpg" -d "D:\desktop" -s "suf test" # without trailing backslash

rimage png "D:\example.jpg" -s "suffix"  -d "D:\desktop\" # backslash at the end

Contributing

Read the contribution guide for build instructions and guidelines.

License

Rimage is dual-licensed under Apache License 2.0 and MIT License. You can choose either license for your use.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Changelog

View the Changelog for version-specific changes.

Dependencies

~16–31MB
~431K SLoC