imgo

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2022 License: MIT Imports: 26 Imported by: 5

README

ImGo

English | 简体中文

Github stars GitHub go.mod Go version GitHub tag (latest by date) GoDoc Go Report Card

Introduction

Image Golang => Img Go => ImGo [ˈɪmɡəʊ]

ImGo is an open source Golang image handling and manipulation library. It provides an easier and expressive way to create, edit, and compose images.

Installation

go get -u github.com/fishtailstudio/imgo

Documentation

English Documentation | 简体中文文档

Usage

package main

import "github.com/fishtailstudio/imgo"

func main() {
    imgo.Load("background.png").
        Resize(250, 350).
        Insert("gopher.png", 50, 50).
        Save("out.png")
}

Maintainers

@fishtailstudio

Contributing

Feel free to dive in! Open an Issue or submit PRs.

Give a Star ! ⭐

If you like or are using this project, please give it a star. Thanks!

License

MIT © fishtailstudio

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSourceImageIsNil          = errors.New("source image is nil")
	ErrSourceNotSupport          = errors.New("source not support")
	ErrSourceStringIsEmpty       = errors.New("source string is empty")
	ErrSourceImageNotSupport     = errors.New("source image not support")
	ErrSaveImageFormatNotSupport = errors.New("save image format not support")
)

Functions

func Color2Hex

func Color2Hex(c color.Color) string

Color2Hex converts a color.Color to its hex string representation.

func GetImageType

func GetImageType(bytes []byte) (ext string, mimetype string, decoder func(r io.Reader) (image.Image, error), err error)

GetImageType returns the extension, mimetype and corresponding decoder function of the image. It judges the image by its first few bytes called magic number.

func Image2RGBA

func Image2RGBA(img image.Image) *image.RGBA

Image2RGBA converts an image to RGBA.

Types

type FlipType

type FlipType int

Flip Type

const (
	Vertical FlipType = iota
	Horizontal
)

type Image

type Image struct {
	Error error
	// contains filtered or unexported fields
}

func Canvas

func Canvas(width, height int, fillColor ...color.Color) *Image

Canvas create a new empty image.

func Load

func Load(source interface{}) *Image

Load an image from source. source can be a file path, a URL, a base64 encoded string, an *os.File, an image.Image or a byte slice.

func LoadFromBase64

func LoadFromBase64(base64Str string) (i *Image)

LoadFromBase64 loads an image from a base64 encoded string.

func LoadFromFile

func LoadFromFile(file *os.File) (i *Image)

LoadFromFile loads an image from a file.

func LoadFromImage

func LoadFromImage(img image.Image) (i *Image)

LoadFromImage loads an image from an instance of image.Image.

func LoadFromImgo added in v0.0.2

func LoadFromImgo(i *Image) *Image

LoadFromImgo loads an image from an instance of Image.

func LoadFromPath

func LoadFromPath(path string) (i *Image)

LoadFromPath loads an image from a path.

func LoadFromUrl

func LoadFromUrl(url string) (i *Image)

LoadFromUrl loads an image when the source is an url.

func (*Image) Blur

func (i *Image) Blur(ksize int) *Image

Blur returns a blurred image. ksize is filter kernel size, it must be a odd number.

func (*Image) BorderRadius

func (i *Image) BorderRadius(radius float64) *Image

BorderRadius draws rounded corners on the image with given radius.

func (Image) Bounds

func (i Image) Bounds() image.Rectangle

Bounds returns the bounds of the image.

func (*Image) Circle

func (i *Image) Circle(x, y, radius int, c color.Color) *Image

Circle draws a circle at given center coordinate (x, y) with given radius and color.

func (*Image) Crop

func (i *Image) Crop(x, y, width, height int) *Image

Crop Cut out a rectangular part of the current image with given width and height.

func (*Image) Ellipse

func (i *Image) Ellipse(x, y, width, height int, c color.Color) *Image

Ellipse draws an ellipse at given center coordinate (x, y) with given width and height and color.

func (Image) Extension

func (i Image) Extension() string

Extension returns the extension of the image.

func (Image) Filesize

func (i Image) Filesize() int64

Filesize returns the filesize of the image, if instance is initiated from an actual file.

func (*Image) Flip

func (i *Image) Flip(flipType FlipType) *Image

Flip mirror the image vertically or horizontally.

func (*Image) GaussianBlur

func (i *Image) GaussianBlur(ksize int, sigma float64) *Image

GaussianBlur returns a blurred image. ksize is Gaussian kernel size sigma is Gaussian kernel standard deviation.

func (*Image) Grayscale

func (i *Image) Grayscale() *Image

Grayscale converts the image to grayscale.

func (Image) Height

func (i Image) Height() int

Height returns the height of the image.

func (Image) HttpHandler

func (i Image) HttpHandler(w http.ResponseWriter, r *http.Request)

HttpHandler responds the image as an HTTP handler.

func (*Image) Insert

func (i *Image) Insert(source interface{}, x, y int) *Image

Insert inserts source into the image at given (x, y) coordinate. source can be a file path, a URL, a base64 encoded string, an *os.File, an image.Image, a byte slice or an *Image.

func (*Image) Line

func (i *Image) Line(x1, y1, x2, y2 int, c color.Color, width ...int) *Image

Line draws a line from (x1, y1) to (x2, y2) with given color. TODO: width is not working yet.

func (*Image) MainColor

func (i *Image) MainColor() (res color.RGBA)

MainColor returns the main color of the image

func (Image) Mimetype added in v0.0.2

func (i Image) Mimetype() string

Mimetype returns the mimetype of the image.

func (*Image) Mosaic

func (i *Image) Mosaic(size, x1, y1, x2, y2 int) *Image

Mosaic apply mosaic filter to the image in given rectangle that (x1, y1) and (x2, y2) are the top-left and bottom-right coordinates of the rectangle. size is the size of the pixel.

func (Image) PickColor

func (i Image) PickColor(x, y int) (res color.RGBA)

PickColor returns the color of the pixel at (x, y).

func (*Image) Pixel

func (i *Image) Pixel(x, y int, c color.Color) *Image

Pixel draws a pixel at given (x, y) coordinate with given color.

func (*Image) Pixelate

func (i *Image) Pixelate(size int) *Image

Pixelate apply pixelation filter to the image. size is the size of the pixel.

func (*Image) Rectangle

func (i *Image) Rectangle(x, y, width, height int, c color.Color) *Image

Rectangle draws a rectangle at given coordinate (x, y) with given width and height and color.

func (*Image) Resize

func (i *Image) Resize(width, height int) *Image

Resize resizes the image to the specified width and height.

func (*Image) Rotate

func (i *Image) Rotate(angle int) *Image

Rotate rotates the image clockwise by the specified angle.

func (*Image) Save

func (i *Image) Save(path string, quality ...int) *Image

Save saves the image to the specified path. Only png, jpeg, jpg, tiff and bmp extensions are supported. path is the path the image will be saved to. quality is the quality of the image, between 1 and 100, default is 100, and is only used for jpeg images.

func (Image) String

func (i Image) String() string

String returns the image as a string.

func (*Image) Text

func (i *Image) Text(label string, x, y int, fontPath string, fontColor color.Color, fontSize float64, dpi float64) *Image

Text write a text string to the image at given (x, y) coordinate.

func (*Image) Thumbnail

func (i *Image) Thumbnail(width, height int) *Image

Thumbnail returns a thumbnail of the image with given width and height.

func (Image) ToBase64

func (i Image) ToBase64() string

ToBase64 returns the base64 encoded string of the image.

func (Image) ToImage

func (i Image) ToImage() image.Image

ToImage returns the instance of image.Image of the image.

func (Image) Width

func (i Image) Width() int

Width returns the width of the image.

type ImageManager

type ImageManager struct {
}

type Radius

type Radius struct {
	// contains filtered or unexported fields
}

func (*Radius) At

func (c *Radius) At(x, y int) color.Color

func (*Radius) Bounds

func (c *Radius) Bounds() image.Rectangle

func (*Radius) ColorModel

func (c *Radius) ColorModel() color.Model

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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