Home

Awesome

Vips for go

This package is powered by the blazingly fast libvips image processing library, originally created in 1989 at Birkbeck College and currently maintained by JohnCupitt.

This is a loosely port of sharp an awesome module for node.js built by Lovell Fuller

The typical use case for this high speed package is to convert large images of many formats to smaller, web-friendly JPEG, PNG images of varying dimensions.

The performance of JPEG resizing is typically 8x faster than ImageMagick and GraphicsMagick, based mainly on the number of CPU cores available.

When generating JPEG output all metadata is removed and Huffman tables optimised without having to use separate command line tools like jpegoptim and jpegtran.

Installation

go get github.com/daddye/vips

libvips can take advantage of liborc if present.

Install libvips on Mac OS

brew install homebrew/science/vips --without-fftw --without-libexif --without-libgsf \
  --without-little-cms2 --without-orc --without-pango --without-pygobject3 \
  --without-gobject-introspection --without-python

Install libvips on Linux

Compiling from source is recommended:

sudo apt-get install automake build-essential git gobject-introspection \
  libglib2.0-dev libjpeg-turbo8-dev libpng12-dev gtk-doc-tools
git clone https://github.com/jcupitt/libvips.git
cd libvips
./bootstrap.sh
./configure --enable-debug=no --without-python --without-fftw --without-libexif \
  --without-libgf --without-little-cms --without-orc --without-pango --prefix=/usr
make
sudo make install
sudo ldconfig

Usage

You can use package from the command line (go install github.com/daddye/vips/vips-cmd):

vips-cmd -file test.jpg -width 400 -height 600 > /tmp/test.jpg

Or simply importing the package and then:

options := vips.Options{
	Width:        800,
	Height:       600,
	Crop:         false,
	Extend:       vips.EXTEND_WHITE,
	Interpolator: vips.BILINEAR,
	Gravity:      vips.CENTRE,
	Quality:      95,
}
f, _ := os.Open("/tmp/test.jpg")
inBuf, _ := ioutil.ReadAll(f)
buf, err := vips.Resize(inBuf, options)
if err != nil {
	fmt.Fprintln(os.Stderr, err)
	return
}
// do some with your resized image `buf`

Performance

Test by @lovell

Test environment

The contenders

The task

Decompress a 2725x2225 JPEG image, resize and crop to 720x480, then compress to JPEG.

Results

ModuleInputOutputOps/secSpeed-up
imagemagick-nativebufferbuffer0.971
imagemagickfilefile2.492.6
gmbufferfile3.723.8
gmbufferbuffer3.803.9
gmfilefile3.673.8
gmfilebuffer3.673.8
sharpbufferfile13.6214.0
sharpbufferbuffer12.4312.8
sharpfilefile13.0213.4
sharpfilebuffer11.1511.5
sharp +sharpenfilebuffer10.2610.6
sharp +progressivefilebuffer9.449.7
sharp +sequentialReadfilebuffer11.9412.3

You can expect much greater performance with caching enabled (default) and using 16+ core machines.

Thanks

This module would never have been possible without the help and code contributions of the following people:

License

Copyright (C) 2014 Davide D'Agostino

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.