doc.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. Package imaging provides basic image manipulation functions (resize, rotate, flip, crop, etc.).
  3. This package is based on the standard Go image package and works best along with it.
  4. Image manipulation functions provided by the package take any image type
  5. that implements `image.Image` interface as an input, and return a new image of
  6. `*image.NRGBA` type (32bit RGBA colors, not premultiplied by alpha).
  7. Imaging package uses parallel goroutines for faster image processing.
  8. To achieve maximum performance, make sure to allow Go to utilize all CPU cores:
  9. runtime.GOMAXPROCS(runtime.NumCPU())
  10. Here is the complete example that loads several images, makes thumbnails of them
  11. and joins them together.
  12. package main
  13. import (
  14. "image"
  15. "image/color"
  16. "runtime"
  17. "github.com/disintegration/imaging"
  18. )
  19. func main() {
  20. // use all CPU cores for maximum performance
  21. runtime.GOMAXPROCS(runtime.NumCPU())
  22. // input files
  23. files := []string{"01.jpg", "02.jpg", "03.jpg"}
  24. // load images and make 100x100 thumbnails of them
  25. var thumbnails []image.Image
  26. for _, file := range files {
  27. img, err := imaging.Open(file)
  28. if err != nil {
  29. panic(err)
  30. }
  31. thumb := imaging.Thumbnail(img, 100, 100, imaging.CatmullRom)
  32. thumbnails = append(thumbnails, thumb)
  33. }
  34. // create a new blank image
  35. dst := imaging.New(100*len(thumbnails), 100, color.NRGBA{0, 0, 0, 0})
  36. // paste thumbnails into the new image side by side
  37. for i, thumb := range thumbnails {
  38. dst = imaging.Paste(dst, thumb, image.Pt(i*100, 0))
  39. }
  40. // save the combined image to file
  41. err := imaging.Save(dst, "dst.jpg")
  42. if err != nil {
  43. panic(err)
  44. }
  45. }
  46. */
  47. package imaging