Documentation ¶
Index ¶
- Constants
- func CalculatePt(targetSize image.Point, watermark image.Point, anchor imaging.Anchor, ...) image.Point
- func CalculatePt2(targetSize image.Point, watermark image.Point, anchor imaging.Anchor, ...) image.Point
- func NewRGBA(r image.Rectangle) *image.RGBA
- func Save(img *Image, out io.Writer, format imaging.Format, opts ...imaging.EncodeOption) error
- func SaveToFile(img *Image, filename string, opts ...imaging.EncodeOption) error
- type Image
- func NewImage(src image.Image) *Image
- func OpenLocalFile(filename string, opts ...imaging.DecodeOption) (*Image, error)
- func OpenReader(src io.Reader, opts ...imaging.DecodeOption) (*Image, error)
- func Overlay(background Image, img Image, pos image.Point, opacity float64) *Image
- func Paste(background Image, img Image, pos image.Point) *Image
- func (img *Image) AddWaterMark(watermark *Image, anchor imaging.Anchor, marginX int, marginY int, ...) *Image
- func (img *Image) AdjustBrightness(percentage float64) *Image
- func (img *Image) AdjustContrast(percentage float64) *Image
- func (img *Image) AdjustGamma(gamma float64) *Image
- func (img *Image) AdjustSaturation(percentage float64) *Image
- func (img *Image) AdjustSigmoid(midpoint float64, factor float64) *Image
- func (img *Image) Blur(sigma float64) *Image
- func (img *Image) Clone() *Image
- func (img *Image) Compress(quality int) *Image
- func (img *Image) Convolve3x3(kernel [9]float64) *Image
- func (img *Image) Convolve5x5(kernel [25]float64) *Image
- func (img *Image) Crop(width int, height int, anchor imaging.Anchor) *Image
- func (img *Image) DrawText(content string, fc *fontx.FontConfig, m font.Metrics, anchor imaging.Anchor, ...) (*Image, error)
- func (img *Image) Fill(width int, height int, anchor imaging.Anchor, filter imaging.ResampleFilter) *Image
- func (img *Image) Fit(width int, height int, filter imaging.ResampleFilter) *Image
- func (img *Image) GetSource() image.Image
- func (img *Image) Gray() *Image
- func (img *Image) Height() int
- func (img *Image) Invert() *Image
- func (img *Image) Overlay(top *Image, pos image.Point, opacity float64) *Image
- func (img *Image) Paste(top *Image, pos image.Point) *Image
- func (img *Image) Resize(width int, height int, filter imaging.ResampleFilter) *Image
- func (img *Image) Rotate(angle float64, bgColor color.Color) *Image
- func (img *Image) SetSource(src image.Image) *Image
- func (img *Image) Sharpen(percentage float64) *Image
- func (img *Image) Transverse() *Image
- func (img *Image) Width() int
Constants ¶
const (
DefaultDPI = 72
)
Variables ¶
This section is empty.
Functions ¶
func CalculatePt ¶
func CalculatePt(targetSize image.Point, watermark image.Point, anchor imaging.Anchor, marginX int, marginY int) image.Point
CalculatePt calculates point according to the given point.
func CalculatePt2 ¶
func CalculatePt2(targetSize image.Point, watermark image.Point, anchor imaging.Anchor, marginX int, marginY int) image.Point
CalculatePt calculates point according to the given point.
func SaveToFile ¶
func SaveToFile(img *Image, filename string, opts ...imaging.EncodeOption) error
SaveToFile saves img.Image to file.
Types ¶
type Image ¶
type Image struct {
// contains filtered or unexported fields
}
func OpenLocalFile ¶
func OpenLocalFile(filename string, opts ...imaging.DecodeOption) (*Image, error)
OpenLocalFile gets an Image using a local file.
func OpenReader ¶
OpenReader gets an Image using a reader.
func Overlay ¶
Overlay draws the img image over the background image at given position and returns the combined image. Opacity parameter is the opacity of the img image layer, used to compose the images, it must be from 0.0 to 1.0.
func Paste ¶
Paste pastes the img image to the background image at the specified position and returns the combined image.
func (*Image) AddWaterMark ¶
func (*Image) AdjustBrightness ¶
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. Examples: Decrease image brightness by 15%.
dstImage = imaging.AdjustBrightness(srcImage, -15)
Increase image brightness by 10%.
dstImage = imaging.AdjustBrightness(srcImage, 10)
AdjustBrightness使用百分比参数更改图像的亮度,并返回调整后的图像。 百分比必须在范围内(-100,100)。 百分比= 0给出原始图像。 百分比= -100给出纯黑色图像。 百分比= 100给出纯白图像。
func (*Image) AdjustContrast ¶
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. Examples: Decrease image contrast by 10%.
dstImage = imaging.AdjustContrast(srcImage, -10)
Increase image con
dstImage = imaging.AdjustContrast(srcImage, 20)
使用百分比参数更改图像的对比度并返回调整后的图像。
百分比必须在范围内(-100,100)。
百分比= 0给出原始图像。 百分比= -100给出纯灰色图像。
func (*Image) AdjustGamma ¶
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. Example:
dstImage = imaging.AdjustGamma(srcImage, 0.7)
AdjustGamma对图像执行伽玛校正并返回调整后的图像。 Gamma参数必须为正数。 Gamma = 1.0给出原始图像。 小于1.0的伽玛使图像变暗,大于1.0的伽玛使其变亮。
func (*Image) AdjustSaturation ¶
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). Examples: Increase image saturation by 25%.
dstImage = imaging.AdjustSaturation(srcImage, 25)
Decrease image saturation by 10%.
dstImage = imaging.AdjustSaturation(srcImage, -10)
AdjustSaturation使用百分比参数更改图像的饱和度并返回调整后的图像。 百分比必须在范围(-100,100)内。 百分比= 0给出原始图像。 百分比= 100表示每个像素的饱和度值加倍的图像。 百分比= -100给出的图像的饱和度值为每个像素(灰度)。
func (*Image) AdjustSigmoid ¶
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. Examples: Increase the contrast.
dstImage = imaging.AdjustSigmoid(srcImage, 0.5, 3.0)
Decrease the contrast.
dstImage = imaging.AdjustSigmoid(srcImage, 0.5, -3.0)
AdjustSigmoid使用S形函数更改图像的对比度并返回调整后的图像。 这是一种非线性对比度变化,可用于照片调整,因为它可以保留高光和阴影细节。 中点参数是对比度的中点,必须介于0和1之间,通常为0.5。 因子参数表示增加或减少对比度的程度, 通常在范围(-10,10)内。 如果因子参数为正,则图像对比度增加,否则对比度降低
func (*Image) Blur ¶
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.
Example:
dstImage := imaging.Blur(srcImage, 3.5)
模糊使用高斯函数生成图像的模糊版本。 Sigma参数必须为正,表示图像模糊的程度。
func (*Image) Compress ¶
JPEGQuality compressions jpeg without change the image size.
Quality ranges from 1 to 100 inclusive, higher is better.
在不改变图片尺寸的情况下压缩JPEG图像。图像质量为1-100
func (*Image) Convolve3x3 ¶
Convolve3x3 convolves the image with the specified 3x3 convolution kernel. Default parameters are used if a nil *ConvolveOptions is passed.
Convolve3x3使用指定的3x3卷积内核对图像进行卷积。 如果传递了nil * ConvolveOptions,则使用默认参数。
func (*Image) Convolve5x5 ¶
Convolve5x5 convolves the image with the specified 5x5 convolution kernel. Default parameters are used if a nil *ConvolveOptions is passed.
Convolve5x5使用指定的5x5卷积内核对图像进行卷积。 如果传递了nil * ConvolveOptions,则使用默认参数。
func (*Image) Crop ¶
Crop cuts out a rectangular region with the specified size from the image using the specified anchor point and returns the cropped image. Example:
imaging.CropAnchor(src, 100, 100, imaging.TopLeft)
使用指定的锚点从图像中剪切出具有指定大小的矩形区域,并返回裁剪后的图像。
func (*Image) DrawText ¶
func (img *Image) DrawText(content string, fc *fontx.FontConfig, m font.Metrics, anchor imaging.Anchor, marginX int, marginY int) (*Image, error)
DrawText draws text on the image. anchor is text align, marginX and marginY is the margin to nearest border, if the nearest border is not clear, such as imaging.Center, marginX and marginY always reference to the left border or the top border. example:
im, _ := img.OpenLocalFile("E:\\test\\1.jpg") // 1900x1283 fo, _ := fontx.LoadFont("E:\\test\\Inkfree.ttf") fc := &fontx.FontConfig{ Font: fo.Font, FontSize: 200, Color: color.Black, } metrics := fo.GetMetrics(fc) im.DrawText("Hello", fc, metrics, imaging.BottomRight, 500, 700)
尝试在image上绘制文字。 参数anchor是文字的对齐方式,marginX和marginY是文字的边距。 例如,当anchor=imaging.BottomRight,此时marginX是距离底边的距离,marginY是距离有边框的距离。 当anchor=imaging.BottomRight,此时marginX是距离底边的距离,marginY是距离有边框的距离。
func (*Image) Fill ¶
func (img *Image) Fill(width int, height int, anchor imaging.Anchor, filter imaging.ResampleFilter) *Image
Fill creates an image with the specified dimensions and fills it with the scaled source image. To achieve the correct aspect ratio without stretching, the source image will be cropped. Example:
dstImage := imaging.Fill(srcImage, 800, 600, imaging.Center, imaging.Lanczos)
Fill创建具有指定尺寸的图像,并使用缩放的源图像填充它。 要在不拉伸的情况下获得正确的宽高比,将裁剪源图像。
func (*Image) Fit ¶
Fit scales down the image using the specified resample filter to fit the specified maximum width and height and returns the transformed image. Example:
dstImage := imaging.Fit(srcImage, 800, 600, imaging.Lanczos)
使用指定的重采样滤镜按比例缩小图像以适合指定的最大宽度和高度,并返回变换后的图像。
func (*Image) Overlay ¶
Overlay draws an image over the background image at given position. Opacity parameter is the opacity of the img image layer, used to compose the images, it must be from 0.0 to 1.0.
Examples:
dstImage := imaging.Overlay(backgroundImage, spriteImage, image.Pt(50, 50), 1.0) dstImage := imaging.Overlay(imageOne, imageTwo, image.Pt(0, 0), 0.5)
叠加在给定位置的背景图像上绘制img图像并返回合成图像。 不透明度参数是img图像层的不透明度,用于构成图像,它必须从0.0到1.0。
func (*Image) Paste ¶
Paste pastes the an image to this image at the specified position. Example:
imaging.Paste(src1, src2, image.Pt(10, 100))
粘贴将img图像粘贴到指定位置的背景图像并返回组合图像。
func (*Image) 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.
Example:
dstImage := imaging.Resize(srcImage, 800, 600, imaging.Lanczos)
调整大小使用指定的重采样过滤器将图像调整为指定的宽度和高度,并返回变换后的图像。 如果宽度或高度中的一个为0,则保留图像宽高比。
func (*Image) Rotate ¶
Rotate rotates an image by the given angle counter-clockwise . The angle parameter is the rotation angle in degrees. The bgColor parameter specifies the color of the uncovered zone after the rotation.
旋转将图像逆时针旋转给定角度。 角度参数是以度为单位的旋转角度。 bgColor参数指定旋转后未覆盖区域的颜色。
func (*Image) Sharpen ¶
Sharpen produces a sharpened version of the image. Sigma parameter must be positive and indicates how much the image will be sharpened. Example:
dstImage := imaging.Sharpen(srcImage, 3.5)
锐化生成图像的锐化版本。 Sigma参数必须为正,表示图像将被锐化多少。
func (*Image) Transverse ¶
Transverse flips the image vertically.