// 1. Create a new GIFT filter list 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 imagedst:=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)
USAGE
To create a sequence of filters, the New function is used:
The Bounds method takes the bounds of the source image and returns appropriate bounds for the destination image to fit the result (for example, after using Resize or Rotate filters).
dst:=image.NewRGBA(g.Bounds(src.Bounds()))
There are two methods available to apply these filters to an image:
Draw applies all the added filters to the src image and outputs the result to the dst image starting from the top-left corner (Min point).
g.Draw(dst, src)
DrawAt provides more control. It outputs the filtered src image to the dst image at the specified position using the specified image composition operator. This example is equivalent to the previous:
Two image composition operators are supported by now:
CopyOperator - Replaces pixels of the dst image with pixels of the filtered src image. This mode is used by the Draw method.
OverOperator - Places the filtered src image on top of the dst image. This mode makes sence if the filtered src image has transparent areas.
Empty filter list can be used to create a copy of an image or to paste one image to another. For example:
// Create a new image with dimensions of bgImagedstImage:=image.NewNRGBA(bgImage.Bounds())
// Copy the bgImage to the dstImage.gift.New().Draw(dstImage, bgImage)
// Draw the fgImage over the dstImage at the (100, 100) position.gift.New().DrawAt(dstImage, fgImage, image.Pt(100, 100), gift.OverOperator)
gift.ColorFunc(
func(r0, g0, b0, a0float32) (r, g, b, afloat32) {
r=1-r0// invert the red channelg=g0+0.1// shift the green channel by 0.1b=0// set the blue channel to 0a=a0// preserve the alpha channelreturn
},
)