Small Go package for fast high-level image processing using libvips via C bindings, providing a simple programmatic API.
bimg was designed to be a small and efficient library supporting common image operations such as crop, resize, rotate, zoom or watermark. It can read JPEG, PNG, WEBP natively, and optionally TIFF, PDF, GIF and SVG formats if libvips@8.3+ is compiled with proper library bindings. Lastly AVIF is supported as of libvips@8.9+. For AVIF support libheif needs to be compiled with an applicable AVIF en-/decoder.
bimg is able to output images as JPEG, PNG and WEBP formats, including transparent conversion across them.
bimg uses internally libvips, a powerful library written in C for image processing which requires a low memory footprint
and it’s typically 4x faster than using the quickest ImageMagick and GraphicsMagick settings or Go native image package, and in some cases it’s even 8x faster processing JPEG images.
If you’re looking for an HTTP based image processing solution, see imaginary.
bimg was heavily inspired in sharp, its homologous package built for node.js. bimg is used in production environments processing thousands of images per day.
v1 notice: bimg introduces some minor breaking changes in v1 release.
If you’re using gopkg.in, you can still rely in the v0 without worrying about API breaking changes.
bimg

Small Go package for fast high-level image processing using libvips via C bindings, providing a simple programmatic API.
bimg was designed to be a small and efficient library supporting common image operations such as crop, resize, rotate, zoom or watermark. It can read JPEG, PNG, WEBP natively, and optionally TIFF, PDF, GIF and SVG formats if
libvips@8.3+
is compiled with proper library bindings. Lastly AVIF is supported as oflibvips@8.9+
. For AVIF supportlibheif
needs to be compiled with an applicable AVIF en-/decoder.bimg is able to output images as JPEG, PNG and WEBP formats, including transparent conversion across them.
bimg uses internally libvips, a powerful library written in C for image processing which requires a low memory footprint and it’s typically 4x faster than using the quickest ImageMagick and GraphicsMagick settings or Go native
image
package, and in some cases it’s even 8x faster processing JPEG images.If you’re looking for an HTTP based image processing solution, see imaginary.
bimg was heavily inspired in sharp, its homologous package built for node.js. bimg is used in production environments processing thousands of images per day.
v1 notice:
bimg
introduces some minor breaking changes inv1
release. If you’re usinggopkg.in
, you can still rely in thev0
without worrying about API breaking changes.Contents
Supported image operations
Prerequisites
Note:
libvips
v8.3+ is required for GIF, PDF and SVG support.libvips
v8.9+ is required for AVIF support.libheif
compiled with a AVIF en-/decoder also needs to be present.Installation
libvips
Follow
libvips
installation instructions:https://libvips.github.io/libvips/install.html
Installation script
Note: install script is officially deprecated, it might not work as expected. We recommend following libvips install instructions.
Run the following script as
sudo
(supports OSX, Debian/Ubuntu, Redhat, Fedora, Amazon Linux):If you want to take the advantage of OpenSlide, simply add
--with-openslide
to enable it:The install script requires
curl
andpkg-config
.Performance
libvips is probably the fastest open source solution for image processing. Here you can see some performance test comparisons for multiple scenarios:
Benchmark
Tested using Go 1.5.1 and libvips-7.42.3 in OSX i7 2.7Ghz
Examples
Resize
Rotate
Convert
Force resize
Force resize operation without perserving the aspect ratio:
Custom colour space (black & white)
Custom options
See Options struct to discover all the available fields
Watermark
Fluent interface
Debugging
Run the process passing the
DEBUG
environment variableEnable libvips traces (note that a lot of data will be written in stdout):
You can also dump a core on failure, as John Cuppit said:
Or set the G_DEBUG environment variable:
API
See godoc reference for detailed API documentation.
Authors
Credits
People who recurrently contributed to improve
bimg
in some way.Thank you!
License
MIT - Tomas Aparicio