https://github.com/aprimadi/imagecomp
Golang Image Compression Tool
https://github.com/aprimadi/imagecomp
golang google-pagespeed google-pagespeed-insights image-compression image-optimization mozjpeg pngquant
Last synced: 5 months ago
JSON representation
Golang Image Compression Tool
- Host: GitHub
- URL: https://github.com/aprimadi/imagecomp
- Owner: aprimadi
- Created: 2018-02-11T15:01:29.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-02-13T05:54:43.000Z (almost 8 years ago)
- Last Synced: 2025-08-30T02:40:28.895Z (6 months ago)
- Topics: golang, google-pagespeed, google-pagespeed-insights, image-compression, image-optimization, mozjpeg, pngquant
- Language: Go
- Size: 3.91 KB
- Stars: 23
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# imagecomp
**imagecomp** is an image optimization or compression library written in
Golang that uses `pngquant` and `mozjpeg` under the hood. It is useful for
optimizing images to conform to the Google PageSpeed Insights suggestion
(https://developers.google.com/speed/pagespeed/insights/)
## Dependencies
**imagecomp** requires `pngquant` and `mozjpeg` to be installed.
### On Mac OS X
To install the dependencies using brew do:
```
brew install pngquant
brew install mozjpeg
```
### On Ubuntu
To install `pngquant`:
```
sudo apt-get install pngquant
```
To install `mozjpeg`:
```
git clone https://github.com/mozilla/mozjpeg.git
cd mozjpeg
autoreconf -fiv
./configure
make
sudo make install
sudo ln -s /opt/mozjpeg/bin/cjpeg /usr/bin/cjpeg
sudo ln -s /opt/mozjpeg/bin/jpegtran /usr/bin/jpegtran
```
## Usage
To install, do:
```
go get github.com/aprimadi/imagecomp
go install github.com/aprimadi/imagecomp
```
To optimize images on a given directory do:
```
imagecomp .
```
Multiple directories can also be specified:
```
imagecomp app/assets public/assets
```
## Advanced Options
**imagecomp** accepts two options `-include` and `-exclude` which supports
wildcard character `*`. Use this two options to include and exclude path or
images being optimized. All paths are included by *default*.
Example:
```
imagecomp . -exclude "public/assets/*"
```
Not the use of quote `"`, this is mandatory otherwise the command line (i.e.
bash) will replace the arguments with real path.
Also, note that order matters. For example:
```
imagecomp . -exclude "*" -include "*.jpg"
```
Is not the same as:
```
imagecomp . -include "*.jpg" -exclude "*"
```
Which will excludes all images from being compressed, while the former only
process `.jpg` images.
## Author
Armin Primadi https://github.com/aprimadi
This library were developed by the [engineering team](https://www.dexcode.com/people) at [Dexcode](https://www.dexcode.com).