graphic

package
v0.0.0-...-dddda54 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2024 License: GPL-3.0 Imports: 18 Imported by: 9

README

Go 图形处理库, 主要围绕 Go 自身的 image 库进行增强开发. 支持对图片进行 剪切, 翻转, 缩放, 混合等操作.

关于 API 的命名风格, 以 Clip 操作为例:

  • Clip 对 image.Image 对象进行剪切操作

  • ClipImage 对目标文件进行剪切操作

  • ClipImageCache 对目标文件进行剪切操作, 同时将处理后的文件放到缓 存目录, 下次对同一文件进行相同操作时可以大大提高速度

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clip

func Clip(srcimg image.Image, x, y, w, h int) (dstimg *image.RGBA)

ClipImage clip image object.

func ClipImage

func ClipImage(srcfile, dstfile string, x, y, w, h int, f Format) (err error)

ClipImage clip image file that format is recognized and save it with target format.

func ClipImageCache

func ClipImageCache(srcfile string, x, y, w, h int, f Format) (dstfile string, useCache bool, err error)

ClipImageCache clip any recognized format image and save to cache directory, if already exists, just return it.

func Composite

func Composite(dstimg draw.Image, compimg image.Image, x, y int)

CompositeImage composite two image objects.

func CompositeImage

func CompositeImage(srcfile, compfile, dstfile string, x, y int, f Format) (err error)

CompositeImage composite two image files.

func CompositeImageSet

func CompositeImageSet(srcfile string, compinfos []CompositeInfo, dstfile string, f Format) (err error)

CompositeImageSet composite a set of image files.

func CompositeImageUri

func CompositeImageUri(srcDatauri, compDataUri string, x, y int, f Format) (dstDataUri string, err error)

CompositeImageUri composite two images which format in data uri.

func ConvertDataUriToImage

func ConvertDataUriToImage(dataUri string, dstfile string, f Format) (err error)

ConvertDataUriToImage convert data uri to image file.

func ConvertImage

func ConvertImage(srcfile, dstfile string, f Format) (err error)

ConvertImage converts from any recognized format to target format image.

func ConvertImageCache

func ConvertImageCache(srcfile string, f Format) (dstfile string, useCache bool, err error)

ConvertImageCache converts from any recognized format to cache directory, if already exists, just return it.

func ConvertImageObjectToDataUri

func ConvertImageObjectToDataUri(img image.Image, f Format) (dataUri string, err error)

ConvertImageToDataUri convert image.Image object to data uri.

func ConvertImageToDataUri

func ConvertImageToDataUri(imgfile string) (dataUri string, err error)

ConvertImageToDataUri convert image file to data uri.

func Fill

func Fill(srcimg image.Image, width, height int, style FillStyle) (dstimg *image.RGBA, err error)

FillImage generate a new image in target width and height through source image, there are many fill sytles to choice from.

func FillImage

func FillImage(srcfile, dstfile string, width, height int, style FillStyle, f Format) (err error)

FillImage generate a new image file in target width and height through source image file, there are many fill sytles to choice from.

func FillImageCache

func FillImageCache(srcfile string, width, height int, style FillStyle, f Format) (dstfile string, useCache bool, err error)

FillImageCache generate a new image in target width and height through source image, and save it to cache directory, if already exists, just return it.

func FlipImageHorizontal

func FlipImageHorizontal(srcfile, dstfile string, f Format) (err error)

FlipImageHorizontal flip image in horizontal direction, and save as target format.

func FlipImageVertical

func FlipImageVertical(srcfile, dstfile string, f Format) (err error)

FlipImageVertical flip image in vertical direction, and save as target format.

func GetDominantColorOfImage

func GetDominantColorOfImage(imgfile string) (h, s, v float64, err error)

GetDominantColorOfImage return the dominant hsv color of an image.

func GetImageSize

func GetImageSize(imgfile string) (w, h int, err error)

GetImageSize return image's width and height.

func GetImagesInDir

func GetImagesInDir(dir string) ([]string, error)

func GetPreferScaleClipRect

func GetPreferScaleClipRect(refWidth, refHeight, imgWidth, imgHeight int) (x, y, w, h int, err error)

GetPreferScaleClipRect get the maximum rectangle in center of image which with the same scale to reference width/heigh.

func GetSize

func GetSize(img image.Image) (w, h int)

func Hsv2Rgb

func Hsv2Rgb(h, s, v float64) (r, g, b uint8)

Hsv2Rgb convert color format from HSV(h=[0..360), s,v=[0..1]) to RGB(r, g, b=[0..255]).

func IsSupportedImage

func IsSupportedImage(imgfile string) bool

IsSupportedImage check if image file is supported.

func LoadImage

func LoadImage(imgfile string) (img image.Image, err error)

LoadImage load image file and return image.Image object.

func LoadImageFromDataUri

func LoadImageFromDataUri(dataUri string) (img image.Image, err error)

LoadImageFromDataUri convert data uri to image object.

func NewImageWithColor

func NewImageWithColor(dstfile string, width, height int, r, g, b, a uint8, f Format) (err error)

NewImageWithColor create a new image file with target size and rgba.

func NewWithColor

func NewWithColor(width, height int, r, g, b, a uint8) (dstimg *image.RGBA, err error)

NewWithColor create a new image object with target size and rgba.

func Rgb2Hsv

func Rgb2Hsv(r, g, b uint8) (h, s, v float64)

Rgb2Hsv convert color format from RGB(r, g, b=[0..255]) to HSV(h=[0..360), s,v=[0..1]).

func RotateImageLeft

func RotateImageLeft(srcfile, dstfile string, f Format) (err error)

RotateImageLeft rotate image to left side.

func RotateImageRight

func RotateImageRight(srcfile, dstfile string, f Format) (err error)

RotateImageLeft rotate image to right side.

func SaveImage

func SaveImage(dstfile string, m image.Image, f Format) (err error)

SaveImage save image.Image object to target file.

func Scale

func Scale(srcimg image.Image, newWidth, newHeight int) (dstimg *image.RGBA)

Scale resize image object to new width and height.

func ScaleImage

func ScaleImage(srcfile, dstfile string, newWidth, newHeight int, f Format) (err error)

ScaleImage returns a new image file with the given width and height created by resizing the given image.

func ScaleImageCache

func ScaleImageCache(srcfile string, newWidth, newHeight int, f Format) (dstfile string, useCache bool, err error)

ScaleImageCache resize any recognized format image file and save to cache directory, if already exists, just return it.

func ScaleImagePrefer

func ScaleImagePrefer(srcfile, dstfile string, newWidth, newHeight int, f Format) (err error)

ScaleImagePrefer resize image file to new width and heigh, and maintain the original proportions unchanged.

func ScalePrefer

func ScalePrefer(srcimg image.Image, newWidth, newHeight int) (dstimg *image.RGBA, err error)

ScalePrefer resize image object to new width and heigh, and maintain the original proportions unchanged.

func SniffImageFormat

func SniffImageFormat(file string) (string, error)

func Thumbnail

func Thumbnail(srcimg image.Image, maxWidth, maxHeight int) (dstimg *image.RGBA)

Thumbnail resize image object with limited maximum width and height.

func ThumbnailImage

func ThumbnailImage(srcfile, dstfile string, maxWidth, maxHeight int, f Format) (err error)

ThumbnailImage resize target image file with limited maximum width and height.

func ThumbnailImageCache

func ThumbnailImageCache(srcfile string, maxWidth, maxHeight int, f Format) (dstfile string, useCache bool, err error)

ThumbnailImageCache resize target image file with limited maximum width and height, and save to cache directory, if already exists, just return it.

Types

type CompositeInfo

type CompositeInfo struct {
	File    string
	X, Y, Z int
}

type FillStyle

type FillStyle string

FillStyle define the type to fill image.

const (
	FillTile   FillStyle = "tile"   // 平铺
	FillCenter FillStyle = "center" // 居中
)

type Format

type Format string

Format defines the type of image format.

const (
	FormatPng  Format = "png"
	FormatJpeg Format = "jpeg"
	FormatBmp  Format = "bmp"
	FormatTiff Format = "tiff"
)

Registered image format.

func GetImageFormat

func GetImageFormat(imgfile string) (format Format, err error)

GetImageFormat return image format, such as "png", "jpeg".

Jump to

Keyboard shortcuts

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