tidy up docs and comments
6 files changed
tree: d0c9bfb712f88b1a284d0b749afa4052d3420b12
  1. testdata/
  2. .travis.yml
  3. adjust.go
  4. adjust_test.go
  5. convolution.go
  6. convolution_test.go
  7. doc.go
  8. effects.go
  9. effects_test.go
  10. example_test.go
  11. go.mod
  12. go.sum
  13. histogram.go
  14. histogram_test.go
  15. io.go
  16. io_test.go
  18. README.md
  19. resize.go
  20. resize_test.go
  21. scanner.go
  22. scanner_test.go
  23. tools.go
  24. tools_test.go
  25. transform.go
  26. transform_test.go
  27. utils.go
  28. utils_test.go


GoDoc Build Status Coverage Status Go Report Card

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

All the image processing functions provided by the package accept any image type that implements image.Image interface as an input, and return a new image of *image.NRGBA type (32bit RGBA colors, non-premultiplied alpha).


go get -u github.com/disintegration/imaging



Usage examples

A few usage examples can be found below. See the documentation for the full list of supported functions.

Image resizing

// Resize srcImage to size = 128x128px using the Lanczos filter.
dstImage128 := imaging.Resize(srcImage, 128, 128, imaging.Lanczos)

// Resize srcImage to width = 800px preserving the aspect ratio.
dstImage800 := imaging.Resize(srcImage, 800, 0, imaging.Lanczos)

// Scale down srcImage to fit the 800x600px bounding box.
dstImageFit := imaging.Fit(srcImage, 800, 600, imaging.Lanczos)

// Resize and crop the srcImage to fill the 100x100px area.
dstImageFill := imaging.Fill(srcImage, 100, 100, imaging.Center, imaging.Lanczos)

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:


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

FilterResize result

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


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

Gamma correction

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

Contrast adjustment

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