Go图像过滤工具包:gift

jopen 10年前

包gift提供了一套有用的图像处理过滤器。 纯粹的Go实现,除Go标准库之外没有其它外部的依赖关系。

QUICK START

// 1. Create a new GIFT and add some filters:  g := gift.New(      gift.Resize(800, 0, gift.LanczosResampling),      gift.UnsharpMask(1.0, 1.0, 0.0),  )    // 2. Create a new image of the corresponding size.  // dst is a new target image, src is the original image  dst := image.NewRGBA(g.Bounds(src.Bounds()))    // 3. Use Draw func to apply the filters to src and store the result in dst:  g.Draw(dst, src)

支持的过滤器

  • Transformations

    • Crop(rect image.Rectangle)
    • FlipHorizontal()
    • FlipVertical()
    • Resize(width, height int, resampling Resampling)
    • Rotate(angle float32, backgroundColor color.Color, interpolation Interpolation)
    • Rotate180()
    • Rotate270()
    • Rotate90()
    • Transpose()
    • Transverse()
    </li>
  • Adjustments & effects

    • Brightness(percentage float32)
    • ColorBalance(percentageRed, percentageGreen, percentageBlue float32)
    • ColorFunc(fn func(r0, g0, b0, a0 float32) (r, g, b, a float32))
    • Colorize(hue, saturation, percentage float32)
    • ColorspaceLinearToSRGB()
    • ColorspaceSRGBToLinear()
    • Contrast(percentage float32)
    • Convolution(kernel []float32, normalize, alpha, abs bool, delta float32)
    • Gamma(gamma float32)
    • GaussianBlur(sigma float32)
    • Grayscale()
    • Hue(shift float32)
    • Invert()
    • Maximum(ksize int, disk bool)
    • Mean(ksize int, disk bool)
    • Median(ksize int, disk bool)
    • Minimum(ksize int, disk bool)
    • Saturation(percentage float32)
    • Sepia(percentage float32)
    • Sigmoid(midpoint, factor float32)
    • UnsharpMask(sigma, amount, thresold float32)
    • </ul> </li> </ul>

      过滤器示例

      Resize using lanczos resampling
      gift.Resize(200, 0, gift.LanczosResampling)
      Original image Filtered image
      original filtered
      Resize using linear resampling
      gift.Resize(200, 0, gift.LinearResampling)
      Original image Filtered image
      original filtered
      Crop 90, 90 - 250, 250
      gift.Crop(image.Rect(90, 90, 250, 250))
      Original image Filtered image
      original filtered
      Rotate 90 degrees
      gift.Rotate90()

      项目主页:http://www.open-open.com/lib/view/home/1416985810284