mergi: github.com/noelyahan/mergi Index | Examples | Files

package mergi

import "github.com/noelyahan/mergi"

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

Examples

Package Files

animate.go crop.go doc.go ease.go image.go mask.go merge.go resize.go transition.go watermark.go

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

func Animate Uses

func Animate(imgs []image.Image, delay int) (gif.GIF, error)

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

This example shows how to use the mergi Animate Mergi provides the simplified api to animate any given image array result

Code:

// 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"))

func Crop Uses

func Crop(img image.Image, p1 image.Point, p2 image.Point) (image.Image, error)

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

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

Code:

// 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)
}

func Ease Uses

func Ease(value, start, end float64, ease func(t float64) float64) float64

func Export Uses

func Export(exporter Exporter) error

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

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

Code:

// 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())

func Import Uses

func Import(importer Importer) (image.Image, error)

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

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

Code:

// 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())

func InBack Uses

func InBack(t float64) float64

func InBounce Uses

func InBounce(t float64) float64

func InCirc Uses

func InCirc(t float64) float64

func InCubic Uses

func InCubic(t float64) float64

func InElastic Uses

func InElastic(t float64) float64

func InExpo Uses

func InExpo(t float64) float64

func InOutBack Uses

func InOutBack(t float64) float64

func InOutBounce Uses

func InOutBounce(t float64) float64

func InOutCirc Uses

func InOutCirc(t float64) float64

func InOutCubic Uses

func InOutCubic(t float64) float64

func InOutElastic Uses

func InOutElastic(t float64) float64

func InOutExpo Uses

func InOutExpo(t float64) float64

func InOutQuad Uses

func InOutQuad(t float64) float64

func InOutQuart Uses

func InOutQuart(t float64) float64

func InOutQuint Uses

func InOutQuint(t float64) float64

func InOutSine Uses

func InOutSine(t float64) float64

func InQuad Uses

func InQuad(t float64) float64

func InQuart Uses

func InQuart(t float64) float64

func InQuint Uses

func InQuint(t float64) float64

func InSine Uses

func InSine(t float64) float64

func Linear Uses

func Linear(t float64) float64

func Mask Uses

func Mask(maskImg, original image.Image, maskColor color.RGBA) (image.Image, error)

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 Uses

func Merge(template string, imgs []image.Image) (image.Image, error)

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

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

Code:

// 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)
}

func Opacity Uses

func Opacity(img image.Image, alpha float64) (image.Image, error)

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 OutBack Uses

func OutBack(t float64) float64

func OutBounce Uses

func OutBounce(t float64) float64

func OutCirc Uses

func OutCirc(t float64) float64

func OutCubic Uses

func OutCubic(t float64) float64

func OutElastic Uses

func OutElastic(t float64) float64

func OutExpo Uses

func OutExpo(t float64) float64

func OutQuad Uses

func OutQuad(t float64) float64

func OutQuart Uses

func OutQuart(t float64) float64

func OutQuint Uses

func OutQuint(t float64) float64

func OutSine Uses

func OutSine(t float64) float64

func Resize Uses

func Resize(img image.Image, w, h uint) (image.Image, error)

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

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

Code:

// 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)
}

func Transit Uses

func Transit(imgs1, imgs2, trans []image.Image, mask color.RGBA, start, end, speed float64) []image.Image

func Watermark Uses

func Watermark(watermark, original image.Image, p image.Point) (image.Image, error)

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

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

Code:

// 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)
}

type Exporter Uses

type Exporter interface {
    Export() error
}

Exporter uses to plug any kind of image.Image exporter

type Importer Uses

type Importer interface {
    Import() (image.Image, error)
}

Importer uses to plug any kind of image.Image importer

Package mergi imports 10 packages (graph). Updated 2019-05-20. Refresh now. Tools for package owners.