drawimg

package
v0.0.0-...-83adff0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2020 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnsupportedFormat means the given image format (or file extension) is unsupported.
	ErrUnsupportedFormat = errors.New("imaging: unsupported image format")
)

Functions

func AdjustBrightness

func AdjustBrightness(img image.Image, percentage 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.

Examples:

dstImage = imaging.AdjustBrightness(srcImage, -15) // decrease image brightness by 15%
dstImage = imaging.AdjustBrightness(srcImage, 10) // increase image brightness by 10%

func AdjustContrast

func AdjustContrast(img image.Image, percentage 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 grey image.

Examples:

dstImage = imaging.AdjustContrast(srcImage, -10) // decrease image contrast by 10%
dstImage = imaging.AdjustContrast(srcImage, 20) // increase image contrast by 20%

func AdjustFunc

func AdjustFunc(img image.Image, fn func(c color.NRGBA) color.NRGBA) *image.NRGBA

AdjustFunc performs a gamma correction on the image and returns the adjusted image.

func AdjustGamma

func AdjustGamma(img image.Image, gamma 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.

Example:

dstImage = imaging.AdjustGamma(srcImage, 0.7)

func AdjustSigmoid

func AdjustSigmoid(img 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.

Examples:

dstImage = imaging.AdjustSigmoid(srcImage, 0.5, 3.0) // increase the contrast
dstImage = imaging.AdjustSigmoid(srcImage, 0.5, -3.0) // decrease the contrast

func Blur

func Blur(img image.Image, radius int, sigma float64) *image.NRGBA

Blur produces a blurred version of the image using a Gaussian function.

func Clone

func Clone(img image.Image) *image.NRGBA

Clone returns a copy of the given image.

func Decode

func Decode(r io.Reader) (image.Image, error)

Decode reads an image from r.

func Encode

func Encode(w io.Writer, img image.Image, format Format) error

Encode writes the image img to w in the specified format (JPEG, PNG, GIF, TIFF or BMP).

func Grayscale

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

Grayscale produces grayscale version of the image.

func Int26_6ToString

func Int26_6ToString(x fixed.Int26_6) string

Int26_6ToString convert Int26_6 to string.

func Invert

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

Invert produces inverted (negated) version of the image.

func IsTooBright

func IsTooBright(img image.Image) bool

IsTooBright assume that average brightness higher than 100 is too bright.

func NewNRGBA

func NewNRGBA(width, height int, fillColor color.Color) *image.NRGBA

NewNRGBA creates a new image with the specified width and height, and fills it with the specified color.

func Open

func Open(filename string) (image.Image, error)

Open loads an image from file

func ParseFont

func ParseFont(b []byte) (*truetype.Font, error)

ParseFont just calls the Parse function from the freetype/truetype package.

func Pt

func Pt(x, y int) fixed.Point26_6

Pt converts from a co-ordinate pair measured in pixels to a fixed.Point26_6 co-ordinate pair measured in fixed.Int26_6 units.

func Save

func Save(img image.Image, filename string) (err error)

Save saves the image to file with the specified filename. The format is determined from the filename extension: "jpg" (or "jpeg"), "png", "gif" are supported.

func Sharpen

func Sharpen(img image.Image, radius int, sigma float64) *image.NRGBA

Sharpen produces a sharpened version of the image.

Types

type Context

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

A Context holds the state for drawing text in a given font and size.

func NewContext

func NewContext() *Context

NewContext creates a new Context.

func (*Context) DrawString

func (c *Context) DrawString(s string, p fixed.Point26_6) (fixed.Point26_6, error)

DrawString draws s at p and returns p advanced by the text extent.

func (*Context) FontBox

func (c *Context) FontBox(s string, p fixed.Point26_6) (fixed.Point26_6, error)

FontBox get textbox.

func (*Context) PointToFixed

func (c *Context) PointToFixed(x float64) fixed.Int26_6

PointToFixed converts the given number of points (as in "a 12 point font") into a 26.6 fixed point number of pixels.

func (*Context) SetClip

func (c *Context) SetClip(clip image.Rectangle)

SetClip sets the clip rectangle for drawing.

func (*Context) SetDPI

func (c *Context) SetDPI(dpi float64)

SetDPI sets the screen resolution in dots per inch.

func (*Context) SetDst

func (c *Context) SetDst(dst draw.Image)

SetDst sets the destination image for draw operations.

func (*Context) SetFont

func (c *Context) SetFont(f *truetype.Font)

SetFont sets the font used to draw text.

func (*Context) SetFontSize

func (c *Context) SetFontSize(fontSize float64)

SetFontSize sets the font size in points (as in "a 12 point font").

func (*Context) SetHinting

func (c *Context) SetHinting(hinting font.Hinting)

SetHinting sets the hinting policy.

func (*Context) SetSrc

func (c *Context) SetSrc(src image.Image)

SetSrc sets the source image for draw operations. This is typically an image.Uniform.

type Dao

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

Dao define

func New

func New(c *conf.Config) (d *Dao)

New init dao

func (*Dao) Make

func (d *Dao) Make(c context.Context, mid int64, text string, isUname bool) (dw *DrawImg, err error)

Make create watermark.

type DrawImg

type DrawImg struct {
	CanvasWidth  int
	CanvasHeight int
	File         string

	Canvas *image.NRGBA
	// contains filtered or unexported fields
}

DrawImg create img info.

func NewDrawImg

func NewDrawImg(fontfile string, size int) (w *DrawImg)

NewDrawImg create new img.

func (*DrawImg) Draw

func (w *DrawImg) Draw(text, savepath string, isLeft bool) (err error)

Draw write text to the left or right of img.

func (*DrawImg) ReadSrcImg

func (w *DrawImg) ReadSrcImg(path string) (img image.Image, err error)

ReadSrcImg read an image

type Format

type Format int

Format is an image file format.

const (
	JPEG Format = iota
	PNG
	GIF
)

Image file formats.

func (Format) String

func (f Format) String() string

Jump to

Keyboard shortcuts

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