imgo

package module
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2022 License: MIT Imports: 26 Imported by: 0

README

ImGo

English | 简体中文

GitHub go.mod Go version GitHub tag (latest by date) GoDoc

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.

Install

go get -u github.com/fishtailstudio/imgo

Documentation

Usage

package main

import (
    "github.com/fishtailstudio/imgo"
    "image/color"
)

func main() {
    imgo.Canvas(500, 500, color.Black).
        Insert("gopher.png", 100, 100).
        Save("out.png")
}

Maintainers

@fishtailstudio

Contributing

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

Contributors

This project exists thanks to all the people who contribute.

Give a Star! ⭐

If you like or are using this project to learn or start your solution, please give it a star. Thanks!

License

MIT © Wen Yu

Documentation

Index

Constants

View Source
const (
	TopLeft = iota
)

Variables

View Source
var (
	ErrFileNotSupport            = errors.New("file not support")
	ErrSourceImageIsNil          = errors.New("imgo load source image is nil")
	ErrSourceNotSupport          = errors.New("imgo load source not support")
	ErrSourceStringIsEmpty       = errors.New("imgo load source string is empty")
	ErrSourceImageNotSupport     = errors.New("imgo load 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, mime 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 several bytes called magic number.

func Image2RGBA

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

Image2RGBA converts an image to RGBA.

func NormalizeKernel

func NormalizeKernel(kernel [][]float64)

NormalizeKernel normalizes a kernel.

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 any) *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 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) 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 file 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) ImageFilter

func (i *Image) ImageFilter(kernel [][]float64) *Image

ImageFilter returns a filtered image.

func (*Image) ImageFilterFast

func (i *Image) ImageFilterFast(kernel [][]float64) *Image

ImageFilterFast returns a filtered image with Goroutine.

func (*Image) Insert

func (i *Image) Insert(source any, 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 in the image

func (Image) Mime

func (i Image) Mime() string

Mime returns the file mime type 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) RadiusBorder

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

RadiusBorder draws a border around the image using the given radius.

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