Go圖像過濾工具包:gift
包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)</pre>
支持的過濾器
-
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()
-
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)
過濾器示例
Resize using lanczos resampling
gift.Resize(200, 0, gift.LanczosResampling)
Original image | Filtered image |
---|---|
![]() |
![]() |
Resize using linear resampling
gift.Resize(200, 0, gift.LinearResampling)
Original image | Filtered image |
---|---|
![]() |
![]() |
Crop 90, 90 - 250, 250
gift.Crop(image.Rect(90, 90, 250, 250))
Original image | Filtered image |
---|---|
![]() |
![]() |
Rotate 90 degrees
gift.Rotate90()
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!