Documentation ¶
Overview ¶
Package mergi implements a image manipulation library mainly focusing on merge. See http://mergi.io for more information about mergi.
Mergi library supports
Merge Crop Resize Watermark Animate Import Export
Index ¶
- Variables
- func Animate(imgs []image.Image, delay int) (gif.GIF, error)
- func Crop(img image.Image, p1 image.Point, p2 image.Point) (image.Image, error)
- func Ease(value, start, end float64, ease func(t float64) float64) float64
- func Export(exporter Exporter) error
- func Import(importer Importer) (image.Image, error)
- func InBack(t float64) float64
- func InBounce(t float64) float64
- func InCirc(t float64) float64
- func InCubic(t float64) float64
- func InElastic(t float64) float64
- func InExpo(t float64) float64
- func InOutBack(t float64) float64
- func InOutBounce(t float64) float64
- func InOutCirc(t float64) float64
- func InOutCubic(t float64) float64
- func InOutElastic(t float64) float64
- func InOutExpo(t float64) float64
- func InOutQuad(t float64) float64
- func InOutQuart(t float64) float64
- func InOutQuint(t float64) float64
- func InOutSine(t float64) float64
- func InQuad(t float64) float64
- func InQuart(t float64) float64
- func InQuint(t float64) float64
- func InSine(t float64) float64
- func Linear(t float64) float64
- func Mask(maskImg, original image.Image, maskColor color.RGBA) (image.Image, error)
- func Merge(template string, imgs []image.Image) (image.Image, error)
- func Opacity(img image.Image, alpha float64) (image.Image, error)
- func OutBack(t float64) float64
- func OutBounce(t float64) float64
- func OutCirc(t float64) float64
- func OutCubic(t float64) float64
- func OutElastic(t float64) float64
- func OutExpo(t float64) float64
- func OutQuad(t float64) float64
- func OutQuart(t float64) float64
- func OutQuint(t float64) float64
- func OutSine(t float64) float64
- func Resize(img image.Image, w, h uint) (image.Image, error)
- func Transit(imgs1, imgs2, trans []image.Image, mask color.RGBA, start, end, speed float64) []image.Image
- func Watermark(watermark, original image.Image, p image.Point) (image.Image, error)
- type Exporter
- type Importer
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var MaskBlack = color.RGBA{0, 0, 0, 0}
MaskBlack provides black masking
var MaskWhite = color.RGBA{255, 255, 255, 0}
MaskWhite provides white masking
Functions ¶
func Animate ¶
Animate uses go standard image.Image type array and delay input to returns a gif animation
this type can be exported via mergi.Export function
for more animate examples https://github.com/noelyahan/mergi/examples/animate
Example (Animating) ¶
This example shows how to use the mergi Animate Mergi provides the simplified api to animate any given image array result
package main import ( "github.com/noelyahan/impexp" "github.com/noelyahan/mergi" "image" "log" ) func main() { // Get the image content by passing image path url or file path img1, err := mergi.Import(impexp.NewFileImporter("testdata/avocado-3210885_960_720.jpg")) if err != nil { log.Fatalf("failed to load via local: %s", err) } img2, err := mergi.Import(impexp.NewFileImporter("testdata/cherry-3074284_960_720.jpg")) if err != nil { log.Fatalf("failed to load via local: %s", err) } imgFrames := []image.Image{img1, img2} // Image array and delay should be passed here animation, err := mergi.Animate(imgFrames, 20) if err != nil { log.Fatalf("failed to create animation: %s", err) } // Export final result via animation exporter mergi.Export(impexp.NewAnimationExporter(animation, "result.gif")) }
Output:
func Crop ¶
Crop uses go standard image.Image, the starting X, Y position as go standard image.Point crop width and height as image.Point returns the crop image output
for more crop examples https://github.com/noelyahan/mergi/examples/crop
Example (Croping) ¶
This example shows how to use the basic mergi crop Read the byte[] from the file and decode to a go standard image file and saving the import_export image file to disk
package main import ( "github.com/noelyahan/impexp" "github.com/noelyahan/mergi" "image" "log" ) func main() { // Get the image content by passing image path url or file path img, err := mergi.Import(impexp.NewFileImporter("testdata/tiger-2320819_960_720.jpg")) if err != nil { log.Fatalf("failed to open: %s", err) } // Now let's use the mergi's crop API // Set where to start the crop point cropStartPoint := image.Pt(0, 0) // Set crop width and height as point cropSize := image.Pt(495, 600) resultImage, err := mergi.Crop(img, cropStartPoint, cropSize) if err != nil { log.Fatalf("Mergi crop fails due to [%v]", err) } // Let's save the image err = mergi.Export(impexp.NewFileExporter(resultImage, "result.jpg")) if err != nil { log.Fatalf("failed to save: %s", err) } }
Output:
func Export ¶
Export uses to export output do different sources Multiple exporter implementation can be find in io pkg
for more Import usages https://github.com/noelyahan/mergi/examples
Example (Exporting) ¶
This example shows how to use the mergi Export Mergi provides the simplified api to export the final result Mergi expects Exporter interface type Mergi supports base64, file, animation exporters
package main import ( "github.com/noelyahan/impexp" "github.com/noelyahan/mergi" "log" ) func main() { // Get the image content by passing image path url or file path imgFromLocal, err := mergi.Import(impexp.NewFileImporter("testdata/tiger-2320819_960_720.jpg")) if err != nil { log.Fatalf("failed to load via local: %s", err) } // Get the image content by passing image path url or file path // Reference: https://pixabay.com/en/woman-old-senior-female-elderly-1031000/ imageFromURL, err := mergi.Import(impexp.NewURLImporter("https://cdn.pixabay.com/photo/2015/11/07/11/17/woman-1031000__340.jpg")) if err != nil { log.Fatalf("failed to load via url: %s", err) } // Now you can use this returned standard go image type inside Mergi APIS log.Println(imgFromLocal.Bounds(), imageFromURL.Bounds()) }
Output:
func Import ¶
Import uses to import image.Image from different sources Multiple io implementation can be find in io pkg
for more Import usages https://github.com/noelyahan/mergi/examples
Example (Importing) ¶
This example shows how to use the mergi Import Mergi provides the simplified api to load images via URL resource/file path Mergi.Import will return go standard image.Image
package main import ( "github.com/noelyahan/impexp" "github.com/noelyahan/mergi" "log" ) func main() { // Get the image content by passing image path url or file path imgFromLocal, err := mergi.Import(impexp.NewFileImporter("testdata/tiger-2320819_960_720.jpg")) if err != nil { log.Fatalf("failed to load via local: %s", err) } // Get the image content by passing image path url or file path // Reference: https://pixabay.com/en/woman-old-senior-female-elderly-1031000/ imageFromURL, err := mergi.Import(impexp.NewURLImporter("https://cdn.pixabay.com/photo/2015/11/07/11/17/woman-1031000__340.jpg")) if err != nil { log.Fatalf("failed to load via url: %s", err) } // Now you can use this returned standard go image type inside Mergi APIS log.Println(imgFromLocal.Bounds(), imageFromURL.Bounds()) }
Output:
func InOutBounce ¶
func InOutCubic ¶
func InOutElastic ¶
func InOutQuart ¶
func InOutQuint ¶
func Mask ¶
Mask uses go standard image.Image to get the masked image with original image,
Mask simply match the given color and matched with mask image and original to replace alpha values 0, 255 ¶
for more mask examples https://github.com/noelyahan/mergi/examples/mask
func Merge ¶
Merge uses to merge multiple images according to given templates
ex: "TT" - top, top - horizontal merge (2 images)
ex: "TB" - top, bottom - vertical merge (2 images)
for more merge techniques https://github.com/noelyahan/mergi/examples/merge
Example (Merging) ¶
This example shows how to use the basic mergi merge for 2 images Read the byte[] from the file and decode to a go standard image file and saving the import_export image file to disk
package main import ( "github.com/noelyahan/impexp" "github.com/noelyahan/mergi" "image" "log" ) func main() { // Get the image content by passing image path url or file path img, err := mergi.Import(impexp.NewFileImporter("testdata/evraiki-2514543_240_180.jpg")) if err != nil { log.Fatalf("failed to open: %s", err) } // Now let's use the mergi's merge API // Lets define a template to merge 2 images horizontally template := "TT" images := []image.Image{img, img} resultImage, err := mergi.Merge(template, images) if err != nil { log.Fatalf("failed to merge: %s", err) } // Let's save the image err = mergi.Export(impexp.NewFileExporter(resultImage, "result.jpg")) if err != nil { log.Fatalf("failed to save: %s", err) } }
Output:
func Opacity ¶
Opacity uses go standard image.Image to change the alpha channel of the given image,
the floating point alpha amount has to provide with the given image and it'll return the opacity image
for more opacity examples https://github.com/noelyahan/mergi/examples/opacity
func OutElastic ¶
func Resize ¶
Resize uses go standard image.Image, unsigned int for width and height that want to resize returns the resize image output
for more resize examples https://github.com/noelyahan/mergi/examples/resize
Example (Resizing) ¶
This example shows how to use the basic mergi resize Read the byte[] from the file and decode to a go standard image file and saving the import_export image file to disk
package main import ( "github.com/noelyahan/impexp" "github.com/noelyahan/mergi" "log" ) func main() { // Get the image content by passing image path url or file path img, err := mergi.Import(impexp.NewFileImporter("testdata/evraiki-2514543_240_180.jpg")) if err != nil { log.Fatalf("failed to open: %s", err) } // Now let's use the mergi's resize API // Lets resize double of the given image's size width := uint(img.Bounds().Max.X * 2) height := uint(img.Bounds().Max.Y * 2) resultImage, err := mergi.Resize(img, width, height) if err != nil { log.Fatalf("failed to resize: %s", err) } // Let's save the image err = mergi.Export(impexp.NewFileExporter(resultImage, "result.jpg")) if err != nil { log.Fatalf("failed to save: %s", err) } }
Output:
func Watermark ¶
Watermark uses go standard image.Image to get the watermark image and original image that want to watermark,
the position of the watermark has to provide in image.Point then it'll returns the watermarked image output
for more watermark examples https://github.com/noelyahan/mergi/examples/watermark
Example (Watermarking) ¶
This example shows how to use the basic mergi watermark Read the byte[] from the file and decode to a go standard image file and saving the import_export image file to disk
package main import ( "github.com/noelyahan/impexp" "github.com/noelyahan/mergi" "image" "log" ) func main() { // Get the image content by passing image path url or file path imgOriginal, err := mergi.Import(impexp.NewFileImporter("testdata/tiger-2320819_960_720.jpg")) if err != nil { log.Fatalf("failed to open: %s", err) } // Get the image content by passing image path url or file path imgWatermark, err := mergi.Import(impexp.NewFileImporter("./testdata/mergi_logo_watermark.png")) if err != nil { log.Fatalf("failed to open: %s", err) } // Now let's use the mergi's watermark API // Let's position the watermark left top corner p := image.Pt(0, 0) resultImage, err := mergi.Watermark(imgWatermark, imgOriginal, p) if err != nil { log.Fatalf("failed to watermark image: %s", err) } // Let's save the image err = mergi.Export(impexp.NewFileExporter(resultImage, "result.jpg")) if err != nil { log.Fatalf("failed to save: %s", err) } }
Output: