Skip to content

Imgedit is a package that performs image processing such as resizing and trimming.

License

Notifications You must be signed in to change notification settings

icemint0828/imgedit

Repository files navigation

imgedit

GitHub go.mod Go version Go project version Go Go Report Card codecov CodeFactor golang example License: MIT

Overview

Imgedit is a package that performs image processing such as resizing and trimming available on both CLI and GUI.

Features

  • resize
  • trim
  • tile (lay down images)
  • reverse (vertical, horizon)
  • grayscale
  • add string
  • filter (gray, sepia)
  • interactive file format conversion (png, jpeg, gif)
resize trim tile
resize trim tile
reverse horizon reverse vertical add string
reverse horizon reverse vertical add string
filter gray filter sepia
filter gray filter sepia

Usage (Package)

$ go get github.com/icemint0828/imgedit@v1.6.0

An example with file conversion is as follows.

package main

import (
    "github.com/icemint0828/imgedit"
)

func main() {
    fc, _, err := imgedit.NewFileConverter("srcImage.png")
    if err != nil {
        panic(err)
    }
    fc.Filter(imgedit.GrayModel)
    err = fc.SaveAs("dstImage.png", imgedit.Png)
    if err != nil {
        panic(err)
    }
}

It can also work with just convert bytes through io.Writer and io.Reader.

package main

import (
	"bytes"
	"os"

	"github.com/icemint0828/imgedit"
)

func main() {
	srcFile, err := os.Open("srcImage.png")
	if err != nil {
		panic(err)
	}
	defer srcFile.Close()

	bc, _, err := imgedit.NewByteConverter(srcFile)
	bc.ResizeRatio(0.5)

	buffer := bytes.NewBuffer([]byte{})
	_ = bc.WriteAs(buffer, imgedit.Jpeg)

	dstFile, err := os.Create("dstImage.png")
	if err != nil {
		panic(err)
	}
	defer dstFile.Close()

	_, _ = buffer.WriteTo(dstFile)
}

It can also work with just convert image.

package main

import (
    "image/png"
    "os"

    "github.com/icemint0828/imgedit"
)

func main() {
    srcFile, err := os.Open("srcImage.png")
    if err != nil {
        panic(err)
    }
    defer srcFile.Close()
    srcImage, err := png.Decode(srcFile)
    if err != nil {
        panic(err)
    }

    c := imgedit.NewConverter(srcImage)
    c.Resize(500, 500)
    dstImage := c.Convert()

    dstFile, err := os.Create("dstImage.png")
    if err != nil {
        panic(err)
    }
    defer dstFile.Close()
    err = png.Encode(dstFile, dstImage)
    if err != nil {
        panic(err)
    }
}

Usage (CLI)

You can download the executable file from the link below.

Or if you can use brew on mac OS.

$ brew install icemint0828/tap/imgedit

For more information, please use the help command:

$ imgedit -help

Usage (CLI on docker)

You can also run the CLI on docker. This procedure can only convert files under the current working directory(WD).

$ docker run --rm -e WD=$(pwd) -v $(pwd):/mnt ghcr.io/icemint0828/imgedit:latest filter srcImage.png -mode gray

For more information, please use the help command:

$ docker run --rm -e WD=$(pwd) -v $(pwd):/mnt ghcr.io/icemint0828/imgedit:latest -help

Usage (GUI)

You can also use a sample GUI tool that is created with WASM by this package.

Contributing

This project is currently at early stages and is being developed by internal members.

License

imgedit is under MIT license.