https://github.com/noelyahan/mergi
go library for image programming (merge, crop, resize, watermark, animate, ease, transit)
https://github.com/noelyahan/mergi
animate crop easing gif golang image merge resize transition watermark
Last synced: 12 days ago
JSON representation
go library for image programming (merge, crop, resize, watermark, animate, ease, transit)
- Host: GitHub
- URL: https://github.com/noelyahan/mergi
- Owner: noelyahan
- License: mit
- Created: 2018-09-24T03:40:47.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-11-05T05:58:08.000Z (6 months ago)
- Last Synced: 2025-03-03T08:51:26.390Z (about 2 months ago)
- Topics: animate, crop, easing, gif, golang, image, merge, resize, transition, watermark
- Language: Go
- Homepage: http://mergi.io/
- Size: 25.7 MB
- Stars: 237
- Watchers: 7
- Forks: 27
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-go - mergi - Tool & Go library for image manipulation (Merge, Crop, Resize, Watermark, Animate). (Images / Search and Analytic Databases)
- awesome-go - mergi - Imaging 4 terminal lovers (merge, crop, resize, watermark, animate) - ★ 34 (Images)
- awesome-go-extra - mergi - 09-24T03:40:47Z|2020-05-29T19:49:07Z| (Images / Advanced Console UIs)
- awesome-go-zh - mergi
README

![]()
Result | Terminal Code
-----------------------------------|------------------------------------------
 | `mergi -t TT -i https://raw.githubusercontent.com/ashleymcnamara/gophers/master/Facepalm_Gopher.png -r "131 131" -i https://raw.githubusercontent.com/ashleymcnamara/gophers/master/Facepalm_Picard_Gopher.png -r "131 131" -a "sprite 50"`[](https://godoc.org/github.com/noelyahan/mergi)
[](https://travis-ci.com/noelyahan/mergi)
[](https://codecov.io/gh/noelyahan/mergi)
[](https://goreportcard.com/report/github.com/noelyahan/mergi)
[](https://t.me/joinchat/IzEQ3xEXCiRCh8L2q6pTLg)## :tada: Basic Overview
Image manipulation [go library](http://godoc.org/github.com/noelyahan/mergi) plus [cross platform CLI tool](https://github.com/noelyahan/mergi/tree/master/cmd/mergi).
## ⚡ Features
- 🛠 Merge
- ✂️ Crop
- 💣 Resize
- 🖃 Watermark
- 💖 Animate
- 🔥 Easing
- 🦎 Transition
## 🚀 Getting started
### Install via `go get`
To install Mergi, use `go get`, or download the binary file from [Releases](https://github.com/noelyahan/mergi/releases) page.
```bash
$ go get github.com/noelyahan/mergi
```Usage:
```
╔╦╗╔═╗╦═╗╔═╗╦
║║║║╣ ╠╦╝║ ╦║
╩ ╩╚═╝╩╚═╚═╝╩
let's go & make imaging fun
http://mergi.io
version 1.0.0-a string
Enter animation type=[sprite, slide] and the delay to get mergi gif animation ex: smooth 10
-c value
Enter crop points and height and width ex: x y w h
-f string
Enter true if you want to process the final output
-i value
Enter images that want to merge ex: /path/img1 or url
-o string
Enter image outputs file ex: out.png or out.jpg (default "out.png")
-r value
Enter resize width and height of the output ex: 100 200
-t string
Enter a merge template string ex: TBTBTB (default "T")
-w value
Enter watermark image and points to place it, [-r w h] is optional ex: /path/img -r w h x y```
#### 🛠 Merge
Image 1 | Image 2 | Result Image
-----------------------------------|-------------------------------------------|------------------------------------------
| | 
| | ##### `Mergi Tool`
###### Horizontal
```bash
mergi \
-t TT \
-i testdata/mergi_bg_1.png \
-i testdata/mergi_bg_2.png
```###### Vertical
```bash
mergi \
-t TB \
-i testdata/mergi_bg_1.png \
-i testdata/mergi_bg_2.png
```
##### `Mergi Library`
```go
image1, _ := mergi.Import(impexp.NewFileImporter("./testdata/mergi_bg_1.png"))
image2, _ := mergi.Import(impexp.NewFileImporter("./testdata/mergi_bg_2.png"))horizontalImage, _ := mergi.Merge("TT", []image.Image{image1, image2})
mergi.Export(impexp.NewFileExporter(horizontalImage, "horizontal.png"))verticalImage, _ := mergi.Merge("TB", []image.Image{image1, image2})
mergi.Export(impexp.NewFileExporter(verticalImage, "vertical.png"))
```
#### ✂️ Crop
Image | Result Image
-----------------------------------|------------------------------------------
 | ##### `Mergi Tool`
```bash
mergi \
-i testdata/mergi_bg_1.png \
-c "10 40 200 110"
```##### `Mergi Library`
```go
img, _ := mergi.Import(impexp.NewFileImporter("./testdata/mergi_bg_1.png"))
res, _ := mergi.Crop(img, image.Pt(10, 40), image.Pt(200, 110))
mergi.Export(impexp.NewFileExporter(res, "crop.png"))
```
#### 💣 Resize
Image | Result Image
-----------------------------------|-------------------------------------------
 | ##### `Mergi Tool`
```bash
mergi \
-i testdata/mergi_bg_1.png \
-r "180 80"
```##### `Mergi Library`
```go
img, _ := mergi.Import(impexp.NewFileImporter("./testdata/mergi_bg_1.png"))
res, _ := mergi.Resize(img, uint(180), uint(80))
mergi.Export(impexp.NewFileExporter(res, "resize.png"))
```
#### 🖃 Watermark
Image | Watermark Image | Result Image
-----------------------------------|-------------------------------------------|------------------------------------------
 |  | ##### `Mergi Tool`
```bash
mergi \
-i testdata/mergi_bg_1.png \
-w "testdata/mergi_logo_watermark_90x40.png 250 10"
```##### `Mergi Library`
```go
originalImage, _ := mergi.Import(impexp.NewFileImporter("./testdata/mergi_bg_1.png"))
watermarkImage, _ := mergi.Import(impexp.NewFileImporter("./testdata/glass-mergi_logo_watermark_90x40.jpg"))res, _ := mergi.Watermark(watermarkImage, originalImage, image.Pt(250, 10))
mergi.Export(impexp.NewFileExporter(res, "watermark.png"))
```
#### 💖 Animate
Image 1 | Image 2 | Result Animation
-----------------------------------|-------------------------------------------|------------------------------------------
 |  | 
 |  | ##### `Mergi Tool`
###### Sprite Animation
```bash
mergi \
-t "TT" \
-i testdata/mergi_bg_1.png \
-i testdata/mergi_bg_2.png \
-a "sprite 50"
```
###### Smooth Animation
```bash
mergi \
-t "TT" \
-i testdata/mergi_bg_1.png \
-i testdata/mergi_bg_2.png \
-a "smooth 5"
```##### `Mergi Library`
```go
image1, _ := mergi.Import(impexp.NewFileImporter("./testdata/mergi_bg_1.png"))
image2, _ := mergi.Import(impexp.NewFileImporter("./testdata/mergi_bg_2.png"))gif, _ := mergi.Animate([]image.Image{image1, image2}, 50)
mergi.Export(impexp.NewAnimationExporter(gif, "out.gif"))
```
#### 🔥 Easing
[]() | []() | []() | []()
-----------------------|----------------------|----------------------|----------------------

InBounce | 
InBack | 
InOutQuad | 
InSine

InCubic | 
InElastic | 
InOutExpo | 
Linear

InOutBounce | 
InCirc | 
InOutCubic | 
InOutQuart

InOutBack | 
InCubic | 
InOutCirc | 
InOutSine

InExpo | 
OutBounce | 
InQuint##### `Mergi Library`
`Note: Ease function can be applied with any function, in this example it's applied with Watermark function`
```go
// Load background and the square images
square, _ := mergi.Import(impexp.NewFileImporter("./testdata/square.jpg"))
bg, _ := mergi.Import(impexp.NewFileImporter("./testdata/white_bg.jpg"))// Init images frames to add applied ease frames
frames := make([]image.Image, 0)// Init the limts of the Ease
to := bg.Bounds().Max.X - square.Bounds().Max.X
posY := bg.Bounds().Max.Y/2 - square.Bounds().Max.Y/2
speed := 4// Ease from 0 to width of background
for i := 0; i < to; i += speed {
// Apply Easeing function InBounce
posX := mergi.Ease(float64(i), 0, float64(to), mergi.InBounce)
img, _ := mergi.Watermark(square, bg, image.Pt(int(posX), posY))
frames = append(frames, img)
}// For preview example, save as a gif
gif, _ := mergi.Animate(frames, 1)
mergi.Export(impexp.NewAnimationExporter(gif, "out.gif"))
```
#### 🦎 Transition
[]() | []() | []() | []()
-----------------------|----------------------|----------------------|----------------------

SlideBar | 
Ink1 | 
Ink2 | 
Ink3

ScaleUpFastRect | 
ScaleDownFastRect | 
ScaleUpFastCircle | 
ScaleDownFastCircleLearn more [examples](examples)
## 💻 Contribute
- Clone the repository
```bash
$ go get github.com/noelyahan/mergi
```
- Run unit tests
- Fix bug
- Add new feature
- Push
### 🌠 Contributors
| [
Noel](https://twitter.com/noelyahan)
💻 📖 💬 👀 🤔 🎨 |
| :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification.
Contributions of any kind are welcome!
## Star History
[](https://star-history.com/#noelyahan/mergi&Timeline)
### 🔵 License
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details