image_handler

package
v0.0.0-...-d233a18 Latest Latest
Warning

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

Go to latest
Published: May 8, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TopLeft int = iota
	TopRight
	BottomLeft
	BottomRight
	Center
)

Variables

View Source
var (
	// ErrUnsupportedWatermarkType 不支持的水印类型
	ErrUnsupportedWatermarkType = errors.New("Unsupported watermark type.")

	// ErrWatermarkTooLarge 当水印位置距离右下角的范围小于水印图片时,返回错误。
	ErrWatermarkTooLarge = errors.New("Watermark size is too large.")

	//ErrInvalidPos  pos值无效
	ErrInvalidPos = errors.New("Invalid 'pos' value")
)

Functions

func AdjustBrightness

func AdjustBrightness(fileImg image.Image, sigma float64) *image.NRGBA

亮度 AdjustBrightness changes the brightness of the image using the percentage parameter and returns the adjusted image. The percentage must be in range (-100, 100). The percentage = 0 gives the original image. The percentage = -100 gives solid black image. The percentage = 100 gives solid white image. AdjustBrightness使用百分比参数更改图像的亮度,并返回调整后的图像。 百分比必须在范围(-100至100)内。百分比=0表示原始图像。 百分比=-100表示实心黑色图像。百分比=100表示纯白图像。

func AdjustContrast

func AdjustContrast(fileImg image.Image, sigma float64) *image.NRGBA

图像对比度 AdjustContrast changes the contrast of the image using the percentage parameter and returns the adjusted image. The percentage must be in range (-100, 100). The percentage = 0 gives the original image. The percentage = -100 gives solid gray image. AdjustContrast使用百分比参数更改图像的对比度,并返回调整后的图像。 百分比必须在范围(-100到100)内。 百分比=0表示原始图像。百分比=-100表示纯灰色图像。

func AdjustGamma

func AdjustGamma(fileImg image.Image, sigma float64) *image.NRGBA

调整伽玛值 AdjustGamma performs a gamma correction on the image and returns the adjusted image. Gamma parameter must be positive. Gamma = 1.0 gives the original image. Gamma less than 1.0 darkens the image and gamma greater than 1.0 lightens it. AdjustGamma对图像执行gamma校正并返回调整后的图像。Gamma参数必须为正值。 Gamma=1.0提供原始图像。小于1.0的伽马会使图像变暗,大于1.0的伽玛会使其变亮。

func AdjustSaturation

func AdjustSaturation(fileImg image.Image, sigma float64) *image.NRGBA

饱和度 AdjustSaturation changes the saturation of the image using the percentage parameter and returns the adjusted image. The percentage must be in the range (-100, 100). The percentage = 0 gives the original image. The percentage = 100 gives the image with the saturation value doubled for each pixel. The percentage = -100 gives the image with the saturation value zeroed for each pixel (grayscale). AdjustSaturation使用百分比参数更改图像的饱和度,并返回调整后的图像。 百分比必须在(-100,100)范围内。 百分比=0表示原始图像。 百分比=100给出了每个像素的饱和度值加倍的图像。 百分比=-100表示每个像素(灰度)的饱和度值为零的图像。

func AdjustSigmoid

func AdjustSigmoid(fileImg image.Image, midpoint, factor float64) *image.NRGBA

图像非线性对比度 AdjustSigmoid changes the contrast of the image using a sigmoidal function and returns the adjusted image. It's a non-linear contrast change useful for photo adjustments as it preserves highlight and shadow detail. The midpoint parameter is the midpoint of contrast that must be between 0 and 1, typically 0.5. The factor parameter indicates how much to increase or decrease the contrast, typically in range (-10, 10). If the factor parameter is positive the image contrast is increased otherwise the contrast is decreased. AdjustSigmoid 使用 sigmoidal 函数改变图像的对比度,并返回调整后的图像。 这是对照片调整有用的非线性对比度变化,因为它保留了高光和阴影细节。 midpoint参数是对比度的中点,必须在0到1之间,一般为0.5。 factor参数表示对比度增加或减少多少,一般在(-10, 10)范围内。 如果因子参数为正,则图像对比度增加,否则对比度降低。

func Blur

func Blur(fileImg image.Image, sigma float64) *image.NRGBA

模糊 Blur produces a blurred version of the image using a Gaussian function. Sigma parameter must be positive and indicates how much the image will be blurred. 模糊使用高斯函数生成图像的模糊版本。 Sigma参数必须为正值,并指示图像的模糊程度。

func CropCenter

func CropCenter(fileImg image.Image, width, height int) *image.NRGBA

以图片中心裁剪 CropCenter cuts out a rectangular region with the specified size from the center of the image and returns the cropped image. CropCenter 从图像中心切出一个指定大小的矩形区域,并返回裁剪后的图像。

func FlipH

func FlipH(fileImg image.Image) *image.NRGBA

水平翻转图像(从左到右) FlipH flips the image horizontally (from left to right) and returns the transformed image. FlipH 水平翻转图像(从左到右)并返回变换后的图像。

func FlipV

func FlipV(fileImg image.Image) *image.NRGBA

垂直翻转图像(从上到下) FlipV flips the image vertically (from top to bottom) and returns the transformed image. FlipV 垂直翻转图像(从上到下)并返回转换后的图像。

func Grayscale

func Grayscale(fileImg image.Image) *image.NRGBA

灰度 Grayscale produces a grayscale version of the image. 生成图像的灰度版本。

func Invert

func Invert(fileImg image.Image) *image.NRGBA

反转 Invert produces an inverted (negated) version of the image. Invert 生成图像的反转(否定)版本。

func OpenImage

func OpenImage(inFilePath string) (image.Image, error)

打开图像

func Resize

func Resize(fileImg image.Image, width, height int) *image.NRGBA

尺寸调整,Resize Resize resizes the image to the specified width and height using the specified resampling filter and returns the transformed image. If one of width or height is 0, the image aspect ratio is preserved. Resize使用指定的重采样过滤器将图像大小调整为指定的宽度和高度,并返回变换后的图像。 如果宽度或高度之一为0,则图像纵横比将保留。

func Rotate180

func Rotate180(fileImg image.Image) *image.NRGBA

图像逆时针旋转180度 Rotate180 rotates the image 180 degrees counter-clockwise and returns the transformed image. Rotate180 将图像逆时针旋转 180 度并返回变换后的图像。

func Rotate270

func Rotate270(fileImg image.Image) *image.NRGBA

图像逆时针旋转270度 Rotate270 rotates the image 270 degrees counter-clockwise and returns the transformed image. Rotate270 将图像逆时针旋转 270 度并返回变换后的图像。

func Rotate90

func Rotate90(fileImg image.Image) *image.NRGBA

图像逆时针旋转90度 Rotate90 rotates the image 90 degrees counter-clockwise and returns the transformed image. Rotate90 将图像逆时针旋转 90 度并返回变换后的图像。

func Save

func Save(fileImg image.Image, filename string) error

保存图片

func Sharpen

func Sharpen(fileImg image.Image, sigma float64) *image.NRGBA

锐化 Sharpen produces a sharpened version of the image. Sigma parameter must be positive and indicates how much the image will be sharpened. 锐化生成图像的锐化版本。 Sigma参数必须为正数,并指示图像的锐化程度。

func Thumbnail

func Thumbnail(fileImg image.Image, width, height int) *image.NRGBA

缩略图 Thumbnail scales the image up or down using the specified resample filter, crops it to the specified width and hight and returns the transformed image. 缩略图使用指定的重采样过滤器放大或缩小图像,将其裁剪到指定的宽度和高度并返回转换后的图像。

func Transpose

func Transpose(fileImg image.Image) *image.NRGBA

水平翻转图像并逆时针旋转90度 Transpose flips the image horizontally and rotates 90 degrees counter-clockwise. Transpose 水平翻转图像并逆时针旋转 90 度。

func Transverse

func Transverse(fileImg image.Image) *image.NRGBA

垂直翻转图像,逆时针旋转90度 Transverse flips the image vertically and rotates 90 degrees counter-clockwise. Transverse 垂直翻转图像,逆时针旋转90度。

Types

type FontInfo

type FontInfo struct {
	DPI       float64
	FontIndex int
	FontBytes *truetype.Font
	Size      float64 // 文字大小
	Message   string  // 文字内容
	Position  int     // 文字存放位置
	Dx        int     // 文字x轴留白距离
	Dy        int     // 文字y轴留白距离
	R         uint8   // 文字颜色值RGBA中的R值
	G         uint8   // 文字颜色值RGBA中的G值
	B         uint8   // 文字颜色值RGBA中的B值
	A         uint8   // 文字颜色值RGBA中的A值
}

func (*FontInfo) SetParam

func (fi *FontInfo) SetParam(fontId int, rgba_input string, fontSize, dpi float64, x, y, position int, message string)

type Pos

type Pos int

Pos 表示水印的位置

const (
	TopLeftImg     Pos = iota //0 顶部左边
	TopRightImg               //1 顶部右边
	BottomLeftImg             //2 底部左边
	BottomRightImg            //3 底部右边
	CenterImg                 //4 中间
)

水印的位置

type WaterMarkText

type WaterMarkText struct {
	Quality int
}

定义水印类

func (*WaterMarkText) NewTextGifWaterMark

func (w *WaterMarkText) NewTextGifWaterMark(srcFile string, fontInfo []FontInfo) ([]byte, error)

func (*WaterMarkText) NewTextImageWaterMark

func (w *WaterMarkText) NewTextImageWaterMark(staticImg image.Image, fileType string, fontInfo []FontInfo) ([]byte, error)

func (*WaterMarkText) Save

func (w *WaterMarkText) Save(b []byte, dstFile string) error

func (*WaterMarkText) SetParam

func (w *WaterMarkText) SetParam(quality int)

type WatermarkImage

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

WatermarkImage 用于给图片添加水印功能

目前支持 gif、jpeg 和 png 三种图片格式。 若是 gif 图片,则只取图片的第一帧;png 支持透明背景。

func New

func New(r io.Reader, ext string, padding int, pos Pos) (w *WatermarkImage, err error)

New 声明 WatermarkImage 对象

r 为水印图片内容; ext 为水印图片的扩展名,会根据扩展名判断图片类型; padding 为水印在目标图像上的留白大小; pos 图片位置;

func NewForGif

func NewForGif(r io.Reader, padding int, pos Pos) (w *WatermarkImage, err error)

NewForGif 声明 WatermarkImage 对象

r 为水印图片内容; padding 为水印在目标图像上的留白大小; pos 图片位置;

func NewForImage

func NewForImage(wmImg image.Image, padding int, pos Pos) (w *WatermarkImage, err error)

NewForImage 声明 WatermarkImage 对象

wmImg 为水印图片内容; padding 为水印在目标图像上的留白大小; pos 图片位置;

func NewFromFile

func NewFromFile(path string, padding int, pos int) (*WatermarkImage, error)

NewFromFile 从文件声明一个 WatermarkImage 对象

path 为水印文件的路径; padding 为水印在目标图像上的留白大小; pos 水印的位置的代表数字。

func (*WatermarkImage) Mark

func (w *WatermarkImage) Mark(src io.ReadWriteSeeker, ext string) ([]byte, error)

Mark 将水印写入 src 中,由 ext 确定当前图片的类型。

func (*WatermarkImage) MarkFile

func (w *WatermarkImage) MarkFile(path string) ([]byte, error)

MarkFile 给指定的文件打上水印

func (*WatermarkImage) MarkForImage

func (w *WatermarkImage) MarkForImage(bgImg image.Image, ext string) ([]byte, error)

MarkForImage 将水印写入 image.Image 中

func (*WatermarkImage) Save

func (w *WatermarkImage) Save(b []byte, dstFile string) error

Jump to

Keyboard shortcuts

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