kovidgoyal/imaging

Go library for dealing with images, colorspaces, metadata, simple transforms

Go

41

594 commits

updated Oct 7, 2026

See the code

README

Imaging

This is pure Go code that makes working with images actually useable on top of the Go stdlib. In addition to the usual PNG/JPEG/WebP/TIFF/BMP/GIF formats that have been supported forever, this package adds support for animated PNG, animated WebP, Google's new "jpegli" JPEG variant and all the netPBM image formats.

Additionally, this package support color management via ICC profiles and CICP metadata. Opening non-sRGB images automatically converts them to sRGB, so you don't have to think about it. It has full support for ICC v2 and v4 profiles embedded in all the image formats and is extensively tested against the little-cms library.

It also supports loading image metadata in EXIF format and automatically supports the EXIF orientation flag -- on image load the image is transformed based on that tag automatically.

It automatically falls back to ImageMagick when available, for image formats it does not support.

Finally, it provides basic image processing functions (resize, rotate, crop, brightness/contrast adjustments, etc.).

Installation

go get -u github.com/kovidgoyal/imaging

Documentation

https://pkg.go.dev/github.com/kovidgoyal/imaging

Quickstart

img, metadata, err := imaging.OpenAll(path, options...)
img.Resize(128, 128, imaging.Lanczos)
img.SaveAsPNG(path, mode)

There are also convenience scripts that demonstrate this library in action, note that these are mainly for development and as such they only use the pure Go code and do not fallback to ImageMagick:

./to-png some-image.whatever some-image.png
./to-frames some-animated-image.whatever some-animated-image.apng

Imaging supports image resizing using various resampling filters. The most notable ones:

  • Lanczos - A high-quality resampling filter for photographic images yielding sharp results.
  • CatmullRom - A sharp cubic filter that is faster than Lanczos filter while providing similar results.
  • MitchellNetravali - A cubic filter that produces smoother results with less ringing artifacts than CatmullRom.
  • Linear - Bilinear resampling filter, produces smooth output. Faster than cubic filters.
  • Box - Simple and fast averaging filter appropriate for downscaling. When upscaling it's similar to NearestNeighbor.
  • NearestNeighbor - Fastest resampling filter, no antialiasing.

The full list of supported filters: NearestNeighbor, Box, Linear, Hermite, MitchellNetravali, CatmullRom, BSpline, Gaussian, Lanczos, Hann, Hamming, Blackman, Bartlett, Welch, Cosine. Custom filters can be created using ResampleFilter struct.

Resampling filters comparison

Original image:

srcImage

The same image resized from 600x400px to 150x100px using different resampling filters. From faster (lower quality) to slower (higher quality):

FilterResize result
imaging.NearestNeighbordstImage
imaging.LineardstImage
imaging.CatmullRomdstImage
imaging.LanczosdstImage

Gaussian Blur

dstImage := imaging.Blur(srcImage, 0.5)

Sigma parameter allows to control the strength of the blurring effect.

Original imageSigma = 0.5Sigma = 1.5
srcImagedstImagedstImage

Sharpening

dstImage := imaging.Sharpen(srcImage, 0.5)

Sharpen uses gaussian function internally. Sigma parameter allows to control the strength of the sharpening effect.

Original imageSigma = 0.5Sigma = 1.5
srcImagedstImagedstImage

Gamma correction

dstImage := imaging.AdjustGamma(srcImage, 0.75)
Original imageGamma = 0.75Gamma = 1.25
srcImagedstImagedstImage

Contrast adjustment

dstImage := imaging.AdjustContrast(srcImage, 20)
Original imageContrast = 15Contrast = -15
srcImagedstImagedstImage

Brightness adjustment

dstImage := imaging.AdjustBrightness(srcImage, 20)
Original imageBrightness = 10Brightness = -10
srcImagedstImagedstImage

Saturation adjustment

dstImage := imaging.AdjustSaturation(srcImage, 20)
Original imageSaturation = 30Saturation = -30
srcImagedstImagedstImage

Hue adjustment

dstImage := imaging.AdjustHue(srcImage, 20)
Original imageHue = 60Hue = -60
srcImagedstImagedstImage

Acknowledgements

This is a fork of the un-maintained disintegration/imaging project. The color management code was started out from mandykoh/prism and used some code from go-andiamo/iccarus but it was almost completely re-written from scratch.

kovidgoyal/imaging

Go library for dealing with images, colorspaces, metadata, simple transforms

Go

41

594 commits

updated Oct 7, 2026

See the code

README

Imaging

This is pure Go code that makes working with images actually useable on top of the Go stdlib. In addition to the usual PNG/JPEG/WebP/TIFF/BMP/GIF formats that have been supported forever, this package adds support for animated PNG, animated WebP, Google's new "jpegli" JPEG variant and all the netPBM image formats.

Additionally, this package support color management via ICC profiles and CICP metadata. Opening non-sRGB images automatically converts them to sRGB, so you don't have to think about it. It has full support for ICC v2 and v4 profiles embedded in all the image formats and is extensively tested against the little-cms library.

It also supports loading image metadata in EXIF format and automatically supports the EXIF orientation flag -- on image load the image is transformed based on that tag automatically.

It automatically falls back to ImageMagick when available, for image formats it does not support.

Finally, it provides basic image processing functions (resize, rotate, crop, brightness/contrast adjustments, etc.).

Installation

go get -u github.com/kovidgoyal/imaging

Documentation

https://pkg.go.dev/github.com/kovidgoyal/imaging

Quickstart

img, metadata, err := imaging.OpenAll(path, options...)
img.Resize(128, 128, imaging.Lanczos)
img.SaveAsPNG(path, mode)

There are also convenience scripts that demonstrate this library in action, note that these are mainly for development and as such they only use the pure Go code and do not fallback to ImageMagick:

./to-png some-image.whatever some-image.png
./to-frames some-animated-image.whatever some-animated-image.apng

Imaging supports image resizing using various resampling filters. The most notable ones:

  • Lanczos - A high-quality resampling filter for photographic images yielding sharp results.
  • CatmullRom - A sharp cubic filter that is faster than Lanczos filter while providing similar results.
  • MitchellNetravali - A cubic filter that produces smoother results with less ringing artifacts than CatmullRom.
  • Linear - Bilinear resampling filter, produces smooth output. Faster than cubic filters.
  • Box - Simple and fast averaging filter appropriate for downscaling. When upscaling it's similar to NearestNeighbor.
  • NearestNeighbor - Fastest resampling filter, no antialiasing.

The full list of supported filters: NearestNeighbor, Box, Linear, Hermite, MitchellNetravali, CatmullRom, BSpline, Gaussian, Lanczos, Hann, Hamming, Blackman, Bartlett, Welch, Cosine. Custom filters can be created using ResampleFilter struct.

Resampling filters comparison

Original image:

srcImage

The same image resized from 600x400px to 150x100px using different resampling filters. From faster (lower quality) to slower (higher quality):

FilterResize result
imaging.NearestNeighbordstImage
imaging.LineardstImage
imaging.CatmullRomdstImage
imaging.LanczosdstImage

Gaussian Blur

dstImage := imaging.Blur(srcImage, 0.5)

Sigma parameter allows to control the strength of the blurring effect.

Original imageSigma = 0.5Sigma = 1.5
srcImagedstImagedstImage

Sharpening

dstImage := imaging.Sharpen(srcImage, 0.5)

Sharpen uses gaussian function internally. Sigma parameter allows to control the strength of the sharpening effect.

Original imageSigma = 0.5Sigma = 1.5
srcImagedstImagedstImage

Gamma correction

dstImage := imaging.AdjustGamma(srcImage, 0.75)
Original imageGamma = 0.75Gamma = 1.25
srcImagedstImagedstImage

Contrast adjustment

dstImage := imaging.AdjustContrast(srcImage, 20)
Original imageContrast = 15Contrast = -15
srcImagedstImagedstImage

Brightness adjustment

dstImage := imaging.AdjustBrightness(srcImage, 20)
Original imageBrightness = 10Brightness = -10
srcImagedstImagedstImage

Saturation adjustment

dstImage := imaging.AdjustSaturation(srcImage, 20)
Original imageSaturation = 30Saturation = -30
srcImagedstImagedstImage

Hue adjustment

dstImage := imaging.AdjustHue(srcImage, 20)
Original imageHue = 60Hue = -60
srcImagedstImagedstImage

Acknowledgements

This is a fork of the un-maintained disintegration/imaging project. The color management code was started out from mandykoh/prism and used some code from go-andiamo/iccarus but it was almost completely re-written from scratch.

Project health

Overall

5.6/10

Maintained

10/10

Code review

1/10
OpenSSF Scorecard

Latest release

v1.8.23 · Jul 14, 2026

Releases this year

24