imgedit

package module
v1.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2022 License: MIT Imports: 19 Imported by: 0

README

imgedit

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

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)
resizetrimtilereverse horizonreverse verticaladd stringfilter grayfilter sepia
resize trim tile
reverse horizon reverse vertical add string
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.

Documentation

Index

Constants

View Source
const (
	// DefaultFontSize used when font size is not specified in StringOptions
	DefaultFontSize = 100

	// DefaultOutlineWidth used when outline width is not specified in StringOptions
	DefaultOutlineWidth = 100
)

Variables

View Source
var Gif = Extension("gif")

Gif is one of the supported extension

GrayModel convert image to gray

View Source
var Jpeg = Extension("jpeg")

Jpeg is one of the supported extension

View Source
var Png = Extension("png")

Png is one of the supported extension

View Source
var SepiaModel = FilterModel(color.ModelFunc(sepiaModel))

SepiaModel convert image to sepia

View Source
var SupportedExtensions = []Extension{
	Png,
	Jpeg,
	Gif,
}

SupportedExtensions are supported extensions

View Source
var TtfFile []byte

Functions

func NewByteConverter added in v1.4.0

func NewByteConverter(r io.Reader) (ByteConverter, Extension, error)

NewByteConverter create byteConverter

func NewFileConverter added in v1.2.0

func NewFileConverter(srcPath string) (FileConverter, Extension, error)

NewFileConverter create fileConverter

func ReadTtf added in v1.3.0

func ReadTtf(ttfFilePath string) (*truetype.Font, error)

ReadTtf return ttf from file path

func ReadTtfFromByte added in v1.3.0

func ReadTtfFromByte(ttfFile []byte) (*truetype.Font, error)

ReadTtfFromByte return ttf from file byte

func SupportedExtension added in v1.2.0

func SupportedExtension(extension Extension) bool

SupportedExtension return true, if extension is in the SupportedExtensions

Types

type ByteConverter added in v1.4.0

type ByteConverter interface {
	Converter
	WriteAs(io.Writer, Extension) error
}

ByteConverter interface for image edit

type Converter

type Converter interface {
	Resize(x, y int)
	ResizeRatio(ratio float64)
	Trim(left, top, width, height int)
	Reverse(isHorizon bool)
	// Deprecated: Replace Reverse(true).
	ReverseX()
	// Deprecated: Replace Reverse(false).
	ReverseY()
	Filter(filterModel FilterModel)
	// Deprecated: Replace Filter(imgedit.GrayModel).
	Grayscale()
	AddString(text string, options *StringOptions)
	Tile(xLength, yLength int)
	Convert() image.Image
}

Converter interface for image edit

func NewConverter

func NewConverter(image image.Image) Converter

NewConverter create converter

type Extension added in v1.2.0

type Extension string

Extension is image file extension

type FileConverter added in v1.2.0

type FileConverter interface {
	Converter
	SaveAs(string, Extension) error
}

FileConverter interface for image edit

type FilterModel added in v1.3.0

type FilterModel color.Model

FilterModel wrapper

type Font added in v1.3.0

type Font struct {
	// TrueTypeFont use ReadTtf to get font
	TrueTypeFont *truetype.Font
	// Size default 100
	Size float64
	// Color default color.Black
	Color color.Color
}

Font used in the options

type Outline added in v1.3.0

type Outline struct {
	// Color default color.White
	Color color.Color
	// Width from font. 0 <= Width <= 200 recommended
	Width int
}

Outline used in the options

type StringOptions added in v1.3.0

type StringOptions struct {
	// Point left top = (0px, 0px), default center
	Point *image.Point
	// Font
	Font *Font
	// Outline
	Outline *Outline
}

StringOptions options for AddString

Directories

Path Synopsis
examples
internal
app

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL