Goptimize downscales and optimizes images
Go to file
Ralph Slooten 788c6ecf23
Merge pull request #1 from axllent/dependabot/go_modules/golang.org/x/image-0.18.0
Bump golang.org/x/image from 0.15.0 to 0.18.0
2024-06-27 16:45:57 +12:00
.gitignore Switch to axllent/ghru 2019-11-03 19:12:02 +13:00
CHANGELOG.md 0.2.3 2024-04-23 16:38:46 +12:00
exifcopy.go Optionally preserve exif data 2023-11-10 16:39:41 +13:00
go.mod Bump golang.org/x/image from 0.15.0 to 0.18.0 2024-06-26 19:38:46 +00:00
go.sum Bump golang.org/x/image from 0.15.0 to 0.18.0 2024-06-26 19:38:46 +00:00
goptimize.go Switch to kovidgoyal/imaging to address CVE-2023-36308 2024-04-23 16:38:38 +12:00
LICENSE Add license 2019-08-02 23:44:11 +12:00
main.go Optionally preserve exif data 2023-11-10 16:39:41 +13:00
Makefile Remove darwin 386 builds 2023-02-25 23:07:06 +13:00
README.md Update README 2024-04-23 16:38:46 +12:00

Goptimizer - downscales and optimizes images

Go Report Card

Goptimizer is a commandline utility written in Golang. It downscales and optimizes JPEG, PNG, GIF, TIFF and BMP files.

Image downscaling/rotation is done within goptimize (-m <width>x<height>, see Usage), however optimization is done using the following additional tools (if they are installed):

  • jpegtran (libjpeg-turbo-progs) or jpegoptim
  • optipng
  • pngquant
  • gifsicle

Notes

Both jpegoptim & jpegtran have almost identical optimization, so if both are installed then just jpegtran is used for JPG optimization. PNG optimization however will run through both optipng & pngquant (if installed) as this can result in better optimization.

It is highly recommended to install the necessary optimization tools, however they are not required to run goptimize.

Goptimize will remove all exif data from JPEG files, auto-rotating those that depend on it for orientation.

It will also preserve (by default) the file's original modification times (-p=false to disable).

Animated GIF files are not supported and automatically get skipped.

Usage options

Usage: ./goptimize [options] <images>

Options:
  -q, --quality int        quality, JPEG only (default 75)
  -m, --max string         downscale to a maximum width & height in pixels (<width>x<height>)
  -o, --out string         output directory (default overwrites original)
  -p, --preserve           preserve file modification times (default true)
  -t, --threaded           run multi-threaded (use all CPU cores)
  -u, --update             update to latest release
  -v, --version            show version number
  -h, --help               show help
      --jpegtran string    jpegtran binary (default "jpegtran")
      --jpegoptim string   jpegoptim binary (default "jpegoptim")
      --gifsicle string    gifsicle binary (default "gifsicle")
      --pngquant string    pngquant binary (default "pngquant")
      --optipng string     optipng binary (default "optipng")

Examples

  • ./goptimize image.png - optimize a PNG file
  • ./goptimize -m 800x800 * - optimize and downscale all image files to a maximum size of 800x800px
  • ./goptimize -m 1200x0 image.jpg - optimize and downscale a JPG file to a maximum size of width of 1200px
  • ./goptimize -o out/ image.jpg - optimize a JPG file and save it to out/

Install

Download the appropriate binary from the releases, or if you have golang installed

Build requirements

Go >= 1.21 required.

go get github.com/axllent/goptimize

TODO

Some ideas for the future:

  • Dry run
  • Option to copy exif data (how?)