goInterventionImage

package module
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2020 License: MIT Imports: 23 Imported by: 0

README

Go-Intervention-Image

GO Intervention Image is a golang image handling and manipulation library providing an easier and expressive way to create, edit, and compose images.

Gitter MIT license

Installation

go get github.com/xiyoudaodao/go-intervention-image

Code Examples

// open an image file
img, err := NewInterventionImage(&Config{
    FilePath: "./images/test.jpg",
})
if err != nil {
    panic(err)
}

// set watermark
img.AddWaterMarkImg("", &WaterMarkConfig{
    DestPosition: " left  top ",
})
img.AddWaterMarkImg("", &WaterMarkConfig{
    DestPosition: " right  buttom ",
})
img.AddWaterMarkText("this is a testing", &WaterMarkConfig{
    DestPosition: " right  top ",
})
img.AddWaterMarkText("this is a testing", &WaterMarkConfig{
    DestPosition: " left  buttom ",
})

// resize image instance
img.Resize(300, 600)

// save image in desired format, save default jpeg
img.Save("test", 80)
img.SaveToJPG("test", 80)
img.SaveToPNG("test")

//or save to stream, default webp
img.SaveToStream(80)

//creates valid code
img, err := NewInterventionImage(nil)
if err != nil {
    panic(err)
}
verificationCode, _ := img.MakeVerificationCode(6, 100, 30)
imageByte, _ := img.SaveToWEBPStream(80)
//Display images in HTML
<img src=`data:image/webp;base64,${imageByte}`>

Configuration

//Used to initialize the configuration
//There are (Image/NewNRGBA/FilePath) three ways to initialize a picture. If not, a blank picture with a black background is created.
//SaveFilefolder used to set the folder for file saving. The default is the program execution directory.
type Config struct {
	Image          image.Image
	NewNRGBA       *image.NRGBA
	FilePath       string
	SaveFilefolder string
}

//Image watermark configuration item
//FontPath Custom font path, The format is TTF
//Fontbase64 Custom font path, TTF transfer base64
//FontSize Custom font size, The default value is 12
//FontDPI The default value is 72
//DestX, DestY Specifies where the watermark appears in the image
//DestPosition Describes where the watermark appears in the image,support('LEFT TOP'|'LEFT BUTTOM'|'RIGHT TOP'|'RIGHT BUTTOM'|'CENTER CENTER'),Case insensitive
//WaterMarkColor Specifies the watermark text color, If not specified, the text color (white and black) is set according to the background color of the picture
type WaterMarkConfig struct {
	FontPath       string
	Fontbase64     *[]byte
	FontSize       float64
	FontDPI        float64
	DestX          int
	DestY          int
	DestPosition   string
	WaterMarkColor color.RGBA
}

Contributing

Contributions to the Go Intervention Image library are welcome.

License

© xiyoudaodao, 2020~time.Now

Released under the MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteExtraSpace

func DeleteExtraSpace(s string) string

func NewInterventionImage

func NewInterventionImage(config *Config) (i *interventionImage, err error)

func ParseInt64

func ParseInt64(i interface{}) int64

func RandomString

func RandomString(n int) string

Types

type Config

type Config struct {
	Image          image.Image
	NewNRGBA       *image.NRGBA
	FilePath       string
	SaveFilefolder string
}

Used to initialize the configuration There are (Image/NewNRGBA/FilePath) three ways to initialize a picture. If not, a blank picture with a black background is created. SaveFilefolder used to set the folder for file saving. The default is the program execution directory.

type WaterMarkConfig

type WaterMarkConfig struct {
	FontPath       string
	Fontbase64     *[]byte
	FontSize       float64
	FontDPI        float64
	DestX          int
	DestY          int
	DestPosition   string
	WaterMarkColor color.RGBA
}

Image watermark configuration item FontPath Custom font path, The format is TTF Fontbase64 Custom font path, TTF transfer base64 FontSize Custom font size, The default value is 12 FontDPI The default value is 72 DestX, DestY Specifies where the watermark appears in the image DestPosition Describes where the watermark appears in the image,support('LEFT TOP'|'LEFT BUTTOM'|'RIGHT TOP'|'RIGHT BUTTOM'|'CENTER CENTER'),Case insensitive WaterMarkColor Specifies the watermark text color, If not specified, the text color (white and black) is set according to the background color of the picture

Jump to

Keyboard shortcuts

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