Documentation
¶
Index ¶
- func Degrees(radians float64) float64
- func EncodeJPG(w io.Writer, im image.Image, opt *jpeg.Options) error
- func EncodePNG(w io.Writer, im image.Image) error
- func FontNewFace(f *opentype.Font, points float64, hinting ...font.Hinting) (font.Face, error)
- func FontParse(raw []byte) (*opentype.Font, error)
- func ImageToRGBA(src image.Image) *image.RGBA
- func LoadFontFace(path string, points float64) (font.Face, error)
- func LoadFontFaceFromBytes(raw []byte, points float64) (font.Face, error)
- func LoadFontFaceFromFS(fsys fs.FS, path string, points float64) (font.Face, error)
- func LoadFontFaceFromReader(r io.Reader, points float64) (font.Face, error)
- func LoadImage(path string) (image.Image, error)
- func LoadImageFromBytes(raw []byte) (image.Image, error)
- func LoadImageFromFS(fsys fs.FS, path string) (image.Image, error)
- func LoadImageFromReader(r io.Reader) (image.Image, error)
- func LoadJPG(path string) (image.Image, error)
- func LoadJPGFromBytes(raw []byte) (image.Image, error)
- func LoadJPGFromFS(fsys fs.FS, path string) (image.Image, error)
- func LoadJPGFromReader(r io.Reader) (image.Image, error)
- func LoadPNG(path string) (image.Image, error)
- func LoadPNGFromBytes(raw []byte) (image.Image, error)
- func LoadPNGFromFS(fsys fs.FS, path string) (image.Image, error)
- func LoadPNGFromReader(r io.Reader) (image.Image, error)
- func ParseHexColor(x string) (r, g, b, a int)
- func RGBAToImage(src *image.RGBA) image.Image
- func Radians(degrees float64) float64
- func SaveJPG(path string, im image.Image, quality ...int) error
- func SavePNG(path string, im image.Image) error
- type Align
- type Context
- func (dc *Context) AppendFrame()
- func (dc *Context) AsMask() *image.Alpha
- func (dc *Context) Clear()
- func (dc *Context) ClearPath()
- func (dc *Context) Clip()
- func (dc *Context) ClipPreserve()
- func (dc *Context) ClosePath()
- func (dc *Context) CubicTo(x1, y1, x2, y2, x3, y3 float64)
- func (dc *Context) DrawArc(x, y, r, angle1, angle2 float64)
- func (dc *Context) DrawCircle(x, y, r float64)
- func (dc *Context) DrawEllipse(x, y, rx, ry float64)
- func (dc *Context) DrawEllipticalArc(x, y, rx, ry, angle1, angle2 float64)
- func (dc *Context) DrawImage(im image.Image, x, y int)
- func (dc *Context) DrawImageAnchored(im image.Image, x, y int, ax, ay float64)
- func (dc *Context) DrawLine(x1, y1, x2, y2 float64)
- func (dc *Context) DrawPoint(x, y, r float64)
- func (dc *Context) DrawRectangle(x, y, w, h float64)
- func (dc *Context) DrawRegularPolygon(n int, x, y, r, rotation float64)
- func (dc *Context) DrawRoundedRectangle(x, y, w, h, r float64)
- func (dc *Context) DrawString(s string, x, y float64)
- func (dc *Context) DrawStringAnchored(s string, x, y, ax, ay float64)
- func (dc *Context) DrawStringWrapped(s string, x, y, ax, ay, width, lineSpacing float64, align Align)
- func (dc *Context) EncodeJPG(w io.Writer, o *jpeg.Options) error
- func (dc *Context) EncodePNG(w io.Writer) error
- func (dc *Context) Fill()
- func (dc *Context) FillPreserve()
- func (dc *Context) FontHeight() float64
- func (dc *Context) GetCurrentPoint() (Point, bool)
- func (dc *Context) GetFrame() []image.Image
- func (dc *Context) Height() int
- func (dc *Context) Identity()
- func (dc *Context) Image() image.Image
- func (dc *Context) InvertMask()
- func (dc *Context) InvertY()
- func (dc *Context) LineTo(x, y float64)
- func (dc *Context) LoadFontFace(path string, points float64) error
- func (dc *Context) LoadFontFaceFromBytes(raw []byte, points float64) error
- func (dc *Context) LoadFontFaceFromFS(fsys fs.FS, path string, points float64) error
- func (dc *Context) LoadFontFaceFromReader(r io.Reader, points float64) error
- func (dc *Context) MeasureMultilineString(s string, lineSpacing float64) (width, height float64)
- func (dc *Context) MeasureString(s string) (w, h float64)
- func (dc *Context) MoveTo(x, y float64)
- func (dc *Context) NewSubPath()
- func (dc *Context) Pop()
- func (dc *Context) Push()
- func (dc *Context) QuadraticTo(x1, y1, x2, y2 float64)
- func (dc *Context) ResetClip()
- func (dc *Context) Rotate(angle float64)
- func (dc *Context) RotateAbout(angle, x, y float64)
- func (dc *Context) SaveJPG(path string, quality ...int) error
- func (dc *Context) SavePNG(path string) error
- func (dc *Context) Scale(x, y float64)
- func (dc *Context) ScaleAbout(sx, sy, x, y float64)
- func (dc *Context) SetColor(c color.Color)
- func (dc *Context) SetDash(dashes ...float64)
- func (dc *Context) SetDashOffset(offset float64)
- func (dc *Context) SetFillRule(fillRule FillRule)
- func (dc *Context) SetFillRuleEvenOdd()
- func (dc *Context) SetFillRuleWinding()
- func (dc *Context) SetFillStyle(pattern Pattern)
- func (dc *Context) SetFontFace(fontFace font.Face)
- func (dc *Context) SetHexColor(x string)
- func (dc *Context) SetInterpolator(interp draw.Interpolator)
- func (dc *Context) SetLineCap(lineCap LineCap)
- func (dc *Context) SetLineCapButt()
- func (dc *Context) SetLineCapRound()
- func (dc *Context) SetLineCapSquare()
- func (dc *Context) SetLineJoin(lineJoin LineJoin)
- func (dc *Context) SetLineJoinBevel()
- func (dc *Context) SetLineJoinRound()
- func (dc *Context) SetLineWidth(lineWidth float64)
- func (dc *Context) SetMask(mask *image.Alpha) error
- func (dc *Context) SetPixel(x, y int)
- func (dc *Context) SetRGB(r, g, b float64)
- func (dc *Context) SetRGB255(r, g, b int)
- func (dc *Context) SetRGBA(r, g, b, a float64)
- func (dc *Context) SetRGBA255(r, g, b, a int)
- func (dc *Context) SetStrokeStyle(pattern Pattern)
- func (dc *Context) Shear(x, y float64)
- func (dc *Context) ShearAbout(sx, sy, x, y float64)
- func (dc *Context) Stroke()
- func (dc *Context) StrokePreserve()
- func (dc *Context) TransformPoint(x, y float64) (tx, ty float64)
- func (dc *Context) Translate(x, y float64)
- func (dc *Context) Width() int
- func (dc *Context) WordWrap(s string, w float64) []string
- type FillRule
- type Gradient
- type LineCap
- type LineJoin
- type Matrix
- func (a Matrix) Multiply(b Matrix) Matrix
- func (a Matrix) Rotate(angle float64) Matrix
- func (a Matrix) Scale(x, y float64) Matrix
- func (a Matrix) Shear(x, y float64) Matrix
- func (a Matrix) TransformPoint(x, y float64) (tx, ty float64)
- func (a Matrix) TransformVector(x, y float64) (tx, ty float64)
- func (a Matrix) Translate(x, y float64) Matrix
- type Pattern
- type Point
- type RepeatOp
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EncodeJPG ¶
EncodeJPG encodes an image as a JPEG and writes it to the provided io.Writer with optional encoding options.
func FontNewFace ¶
FontNewFace creates a font face from a parsed *opentype.Font with the specified point size and hinting.
func FontParse ¶
FontParse parses TrueType or OpenType font data from a byte slice and returns an *opentype.Font.
func ImageToRGBA ¶
ImageToRGBA converts an image.Image to an *image.RGBA by creating a new *image.RGBA with the same bounds as the source image and copying the image content into it.
func LoadFontFace ¶
LoadFontFace loads a font face from a TrueType or OpenType font file at the specified file path and returns it as a font.Face with the specified point size.
func LoadFontFaceFromBytes ¶
LoadFontFaceFromBytes creates a font face from a byte slice containing TrueType or OpenType font data, and sets the specified point size.
func LoadFontFaceFromFS ¶
LoadFontFaceFromFS loads a font face from a TrueType or OpenType font file at the specified file path within a file system (fs.FS) and returns it as a font.Face with the specified point size.
func LoadFontFaceFromReader ¶
LoadFontFaceFromReader loads a font face from a TrueType or OpenType font file at the specified io.Reader and returns it as a font.Face with the specified point size.
func LoadImage ¶
LoadImage loads an image from the specified file path and returns it as an image.Image. It opens the file, decodes the image, and returns the decoded image.
func LoadImageFromBytes ¶
LoadImageFromBytes decodes an image from a byte slice and returns it as an image.Image.
func LoadImageFromFS ¶
LoadImageFromFS loads an image from the file system provided by a file system (fs.FS) and returns it as an image.Image. It opens the specified file within the file system, decodes the image, and returns the decoded image.
func LoadImageFromReader ¶
LoadImageFromReader loads an image from an io.Reader and returns it as an image.Image. It decodes the image, and returns the decoded image.
func LoadJPG ¶
LoadJPG loads a JPEG image from the specified file path and returns it as an image.Image. It opens the file, decodes the JPEG image, and returns the decoded image.
func LoadJPGFromBytes ¶
LoadJPGFromBytes decodes a JPEG image from a byte slice and returns it as an image.Image.
func LoadJPGFromFS ¶
LoadJPGFromFS loads a JPEG image from the specified file path within a file system (fs.FS) and returns it as an image.Image. It opens the specified file within the file system, decodes the JPEG image, and returns the decoded image.
func LoadJPGFromReader ¶
LoadJPGFromReader loads a JPEG image from an io.Reader and returns it as an image.Image. It decodes the JPEG image, and returns the decoded image.
func LoadPNG ¶
LoadPNG loads a PNG image from the specified file path and returns it as an image.Image. It opens the file, decodes the PNG image, and returns the decoded image.
func LoadPNGFromBytes ¶
LoadPNGFromBytes decodes a PNG image from a byte slice and returns it as an image.Image.
func LoadPNGFromFS ¶
LoadPNGFromFS loads a PNG image from the specified file path within a file system (fs.FS) and returns it as an image.Image. It opens the specified file within the file system, decodes the PNG image, and returns the decoded image.
func LoadPNGFromReader ¶
LoadPNGFromReader loads a PNG image from an io.Reader and returns it as an image.Image. It decodes the PNG image, and returns the decoded image.
func ParseHexColor ¶
ParseHexColor parses a hexadecimal color string (e.g., "#RGB" or "#RRGGBB" or "#RRGGBBAA") and returns the corresponding red (r), green (g), blue (b), and alpha (a) values. If the alpha component is not provided, it defaults to 255 (fully opaque).
func RGBAToImage ¶
RGBAToImage converts an *image.RGBA to an image.Image by creating a new image.Image with the same bounds as the source image and copying the image content into it.
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context represents a 2D rendering context used for drawing operations.
func NewContext ¶
NewContext creates a new rendering context with the specified width and height.
This function initializes a new rendering context with the provided 'width' and 'height' dimensions. The context is used for performing 2D drawing operations, including path rendering, text rendering, and manipulation of the rendering state.
func NewContextForImage ¶
NewContextForImage creates a new rendering context based on an existing image.Image.
This function initializes a new rendering context using the dimensions and content of the provided 'im' image. The context is used for performing 2D drawing operations, including path rendering, text rendering, and manipulation of the rendering state.
func NewContextForRGBA ¶
NewContextForRGBA prepares a context for rendering onto the specified image. No copy is made.
func (*Context) AppendFrame ¶
func (dc *Context) AppendFrame()
AppendFrame appends the current image to the frames slice.
This method appends the current image to the frames slice. It is used for creating animated image.
func (*Context) AsMask ¶
AsMask converts the context's image to a mask.
This method converts the context's image to a mask, which can be used for masking in future rendering operations. The original image is copied to create the mask, and the mask is returned.
func (*Context) Clear ¶
func (dc *Context) Clear()
Clear sets the entire context's image to a uniform color, effectively clearing the rendering area.
This method fills the entire context's image with the specified uniform color, effectively clearing the rendering area. The uniform color is set to the context's current color. The Clear operation overwrites any existing content in the image with the specified color, making the entire image uniform.
func (*Context) ClearPath ¶
func (dc *Context) ClearPath()
ClearPath clears both the fill and stroke paths, and resets the current point.
This method clears both the fill and stroke paths and resets the current point, effectively starting a new subpath.
func (*Context) Clip ¶
func (dc *Context) Clip()
Clip applies the clip operation to the current path and clears the path.
This method applies the clip operation to the current path and clears the path. It uses the ClipPreserve method to define the clipping area for future rendering. After applying the clip, the current path is cleared.
func (*Context) ClipPreserve ¶
func (dc *Context) ClipPreserve()
ClipPreserve applies the clip operation to the current path, preserving the path for future rendering.
This method applies the clip operation to the current path and preserves the path for future rendering. It creates a mask using the current path, and if a mask already exists, it combines the new mask with the existing one. The mask is used to define the clipping area for future rendering.
func (*Context) ClosePath ¶
func (dc *Context) ClosePath()
ClosePath closes the current subpath by adding a straight line to the starting point.
This method closes the current subpath by appending a straight line segment from the current point to the starting point of the subpath. If there is no current subpath, this method has no effect.
func (*Context) CubicTo ¶
CubicTo adds a cubic Bézier curve segment to the current subpath.
This method appends a cubic Bézier curve segment defined by the current point (start point) and three control points (x1, y1, x2, y2, x3, y3) to both the fill and stroke paths. If there is no current subpath, this method behaves as if MoveTo() was called with the starting point coordinates (x1, y1).
func (*Context) DrawArc ¶
DrawArc draws an arc within the specified parameters.
This method draws an arc within a circle with center (x, y) and radius 'r' starting at 'angle1' and ending at 'angle2' (in radians). The arc is drawn as a series of connected line segments.
func (*Context) DrawCircle ¶
DrawCircle draws a circle centered at (x, y) with the specified radius 'r'.
This method draws a circle with center at (x, y) and radius 'r'. The circle is drawn as a series of connected line segments.
func (*Context) DrawEllipse ¶
DrawEllipse draws an ellipse within the specified bounding box.
This method draws an ellipse within the bounding box defined by the center point (x, y) and the radii 'rx' and 'ry'. The ellipse is drawn as a series of connected line segments that approximate the ellipse shape.
func (*Context) DrawEllipticalArc ¶
DrawEllipticalArc draws a series of connected line segments to approximate an elliptical arc.
This method approximates an elliptical arc within the specified bounding box defined by (x, y), width 'rx', and height 'ry'. The arc is drawn between the angles 'angle1' and 'angle2'.
func (*Context) DrawImage ¶
DrawImage draws an image at the specified (x, y) coordinates.
This method draws the given image at the specified (x, y) coordinates in the context's image. The top-left corner of the image will be positioned at the (x, y) coordinates.
func (*Context) DrawImageAnchored ¶
DrawImageAnchored draws an image anchored at the specified (x, y) coordinates. The anchor point is x - w * ax, y - h * ay, where w, h is the size of the image.
This method draws the given image anchored at the specified (x, y) coordinates in the context's image. The anchor point (ax, ay) determines the relative position within the image that aligns with the (x, y) coordinates. For example, (0, 0) represents the top-left corner of the image, (0.5, 0.5) represents the center, and (1, 1) represents the bottom-right corner.
func (*Context) DrawLine ¶
DrawLine draws a straight line segment between two points.
This method draws a straight line segment between the points (x1, y1) and (x2, y2).
func (*Context) DrawPoint ¶
DrawPoint draws a filled circle at the specified point.
This method draws a filled circle with the specified radius (r) centered at the coordinates (x, y).
func (*Context) DrawRectangle ¶
DrawRectangle draws a filled rectangle at the specified coordinates with the given width and height.
This method draws a filled rectangle with its top-left corner at coordinates (x, y), a width of 'w', and a height of 'h'.
func (*Context) DrawRegularPolygon ¶
DrawRegularPolygon draws a regular polygon with 'n' sides.
This method draws a regular polygon with 'n' sides, centered at (x, y) with a given radius 'r'. The 'rotation' parameter specifies the initial rotation angle. The polygon is drawn as a series of connected line segments.
func (*Context) DrawRoundedRectangle ¶
DrawRoundedRectangle draws a filled rounded rectangle with the specified coordinates, dimensions, and corner radius.
This method draws a filled rounded rectangle with its top-left corner at coordinates (x, y), a width of 'w', a height of 'h', and rounded corners with a radius of 'r'.
func (*Context) DrawString ¶
DrawString renders a text string at the specified coordinates.
This method renders the given text string `s` at the specified (x, y) coordinates on the context's image. The text is rendered using the current font face, color, and other text rendering settings of the context. The (x, y) coordinates represent the baseline position for rendering the text.
func (*Context) DrawStringAnchored ¶
DrawStringAnchored renders a text string anchored at the specified coordinates.
This method renders the given text string `s` anchored at the specified (x, y) coordinates on the context's image. The anchor point is determined by the `ax` (X-axis) and `ay` (Y-axis) values, which represent the relative position within the text bounding box. The text is rendered using the current font face, color, and other text rendering settings of the context.
func (*Context) DrawStringWrapped ¶
func (dc *Context) DrawStringWrapped(s string, x, y, ax, ay, width, lineSpacing float64, align Align)
DrawStringWrapped renders a text string wrapped within a specified width.
This method renders the given text string `s` wrapped within the specified `width` while anchored at the (x, y) coordinates. The text is wrapped into multiple lines to fit the given width. The `ax` (X-axis) and `ay` (Y-axis) values determine the anchor point's relative position within the text bounding box, and the `lineSpacing` controls the vertical spacing between lines. The `align` parameter specifies the horizontal alignment of the text.
func (*Context) EncodeJPG ¶
EncodeJPG encodes and writes the contents of the rendering context as a JPEG image to the provided io.Writer with optional options.
This method encodes the image content of the rendering context as a JPEG image and writes it to the specified 'w' writer. You can optionally specify the 'o' parameter of type *jpeg.Options to control the JPEG encoding options, including quality. Higher quality values (e.g., 90 for high quality) result in better image quality.
func (*Context) EncodePNG ¶
EncodePNG encodes and writes the contents of the rendering context as a PNG image to the provided io.Writer.
This method encodes the image content of the rendering context as a PNG image and writes it to the specified 'w' writer.
func (*Context) Fill ¶
func (dc *Context) Fill()
Fill applies the fill operation to the current path and clears the path.
This method applies the fill operation to the current path and clears the path. It uses the FillPreserve method to render the fill and then clears the path, making it ready for further path construction.
func (*Context) FillPreserve ¶
func (dc *Context) FillPreserve()
FillPreserve applies the fill operation to the current path, preserving the path for future rendering.
This method applies the fill operation to the current path and preserves the path for future rendering. It selects the appropriate painter based on the fill pattern and the presence of a mask. It then calls the fill method to render the fill. After the fill is applied, the current path remains intact.
func (*Context) FontHeight ¶
FontHeight returns the height of the currently set font face.
This method returns the height of the font face currently set for text rendering. The height is measured in points.
func (*Context) GetCurrentPoint ¶
GetCurrentPoint returns the current point (cursor position) in the rendering context.
This method retrieves the current cursor position in the rendering context. The current point represents the location where the most recent drawing operation ended or where the cursor was explicitly positioned.
func (*Context) GetFrame ¶
GetFrame returns the frames slice.
This method returns the frames slice. It is used for creating animated image.
func (*Context) Height ¶
Height returns the height of the rendering context.
This method retrieves the height of the rendering context in pixels.
func (*Context) Identity ¶
func (dc *Context) Identity()
Identity resets the current transformation matrix to the identity matrix.
This method sets the transformation matrix of the drawing context to the identity matrix, effectively removing any prior transformations.
func (*Context) Image ¶
Image returns the image.RGBA associated with the rendering context.
This method retrieves the image.RGBA associated with the rendering context. The image.RGBA represents the canvas or target image where the 2D drawing operations are performed and rendered.
func (*Context) InvertMask ¶
func (dc *Context) InvertMask()
InvertMask inverts the current mask or creates a new one if none exists.
This method inverts the current mask if one exists. If no mask is set, it creates a new alpha mask and inverts it. The inverted mask can be used for masking in future rendering operations.
func (*Context) InvertY ¶
func (dc *Context) InvertY()
InvertY inverts the Y-axis of the current transformation.
This method inverts the Y-axis of the current drawing context. It effectively flips the vertical orientation of subsequent drawings.
func (*Context) LineTo ¶
LineTo adds a straight line segment to the current subpath.
This method appends a straight line segment from the current point to the specified coordinates (x, y) to both the fill and stroke paths. If there is no current subpath, this method behaves as if MoveTo() was called with the same coordinates.
func (*Context) LoadFontFace ¶
LoadFontFace loads a font face from a file and sets it for text rendering.
This method loads a font face from the specified file path and sets it for rendering text. The `points` parameter determines the font size in points.
func (*Context) LoadFontFaceFromBytes ¶
LoadFontFaceFromBytes loads a font face from raw font data and sets it for text rendering.
This method loads a font face from raw font data provided as a byte slice and sets it for rendering text. The `points` parameter determines the font size in points.
func (*Context) LoadFontFaceFromFS ¶
LoadFontFaceFromFS loads a font face from a file system (fs.FS) and sets it for text rendering.
This method loads a font face from the file system (fs.FS) and sets it for rendering text. The `points` parameter determines the font size in points.
func (*Context) LoadFontFaceFromReader ¶
LoadFontFaceFromReader loads a font face from an io.Reader and sets it for text rendering.
This method loads a font face from the specified io.Reader and sets it for rendering text. The `points` parameter determines the font size in points.
func (*Context) MeasureMultilineString ¶
MeasureMultilineString measures the width and height of a multiline text string.
This method calculates the dimensions of a multiline text string `s`, taking into account the specified `lineSpacing` factor for vertical line spacing. It returns the width and height of the multiline text in pixels.
func (*Context) MeasureString ¶
MeasureString measures the width and height of a single-line text string.
This method calculates the dimensions of a single-line text string `s` and returns its width and the standard line height (font height).
func (*Context) MoveTo ¶
MoveTo starts a new subpath at the specified point (x, y).
This method begins a new subpath in the rendering context with the current point set to the specified coordinates (x, y). If there was a previous subpath and the current point was set, this method adds that point to the fill path and starts the stroke path from the new point.
func (*Context) NewSubPath ¶
func (dc *Context) NewSubPath()
NewSubPath starts a new subpath without adding any line segments.
This method begins a new subpath without adding any line segments to it. If there was a previous subpath and the current point was set, this method adds that point to the fill path.
func (*Context) Pop ¶
func (dc *Context) Pop()
Pop restores the drawing context to a previously saved state from the context stack.
This method pops the topmost state from the context stack and restores the drawing context to this saved state. It effectively reverts the current drawing state to a previous state that was saved using the Push method.
func (*Context) Push ¶
func (dc *Context) Push()
Push saves the current drawing context by creating a copy of it and pushing it onto the context stack.
This method saves the current state of the drawing context by creating a copy of it and pushing it onto the context stack. You can later restore this state using the Pop method.
func (*Context) QuadraticTo ¶
QuadraticTo adds a quadratic Bézier curve segment to the current subpath.
This method appends a quadratic Bézier curve segment defined by the current point (start point) and two control points (x1, y1 and x2, y2) to both the fill and stroke paths. If there is no current subpath, this method behaves as if MoveTo() was called with the starting point coordinates (x1, y1).
func (*Context) ResetClip ¶
func (dc *Context) ResetClip()
ResetClip clears the current clipping mask.
This method clears the current clipping mask, allowing for unrestricted rendering. It effectively removes any clipping effects applied by previous Clip or ClipPreserve operations.
func (*Context) Rotate ¶
Rotate applies a rotation transformation to the current transformation matrix.
This method rotates the drawing context by the specified angle in radians. It modifies the current transformation matrix to reflect the rotation.
func (*Context) RotateAbout ¶
RotateAbout applies a rotation transformation about a specified point.
This method rotates the drawing context by the specified angle in radians around the point (x, y). It is equivalent to translating the context to the center of rotation, rotating it, and then translating it back to its original position.
func (*Context) SaveJPG ¶
SaveJPG saves the contents of the rendering context as a JPEG image and writes it to disk with optional quality.
This method saves the image content of the rendering context as a JPEG image to the file at the provided 'path'. It uses the image content associated with the rendering context to create the JPEG image. You can optionally specify the 'quality' parameter to control the image quality, with higher values indicating better quality (e.g., 90 for high quality).
func (*Context) SavePNG ¶
SavePNG saves the contents of the rendering context as a PNG image and writes it to disk.
This method saves the image content of the rendering context as a PNG image to the file at the provided 'path'. It uses the image content associated with the rendering context to create the PNG image.
func (*Context) Scale ¶
Scale applies a scaling transformation to the current matrix.
This method scales the drawing context by the specified horizontal (x) and vertical (y) scaling factors. It modifies the current transformation matrix to reflect the scaling.
func (*Context) ScaleAbout ¶
ScaleAbout applies a scaling transformation about a specified point.
This method scales the drawing context by the specified horizontal (sx) and vertical (sy) scaling factors around the point (x, y). It is equivalent to translating the context to the center of scaling, scaling it, and then translating it back to its original position.
func (*Context) SetColor ¶
SetColor sets the fill and stroke color of the rendering context to the specified color.
This method sets both the fill and stroke colors of the rendering context to the specified color 'c'. The 'c' parameter should be a color.Color value representing the desired color.
func (*Context) SetDash ¶
SetDash sets the dash pattern for stroking lines.
This method allows you to set a custom dash pattern for stroking lines. You can provide a sequence of 'dashes' values to specify the lengths of dashes and gaps between them. For example, to create a dashed line with a 10-pixel dash followed by a 5-pixel gap, you can call SetDash(10, 5).
func (*Context) SetDashOffset ¶
SetDashOffset sets the offset for the dash pattern.
This method allows you to set the offset (phase) for the dash pattern when stroking lines. The 'offset' value determines where the dash pattern starts along the path. You can specify the 'offset' in units of the current line width.
func (*Context) SetFillRule ¶
SetFillRule sets the fill rule for determining the interior of filled shapes.
This method allows you to set the fill rule for determining the interior of filled shapes. You can choose from two predefined fill rules: FillRuleWinding and FillRuleEvenOdd.
func (*Context) SetFillRuleEvenOdd ¶
func (dc *Context) SetFillRuleEvenOdd()
SetFillRuleEvenOdd sets the fill rule to Even-Odd for determining the interior of filled shapes.
This method sets the fill rule to Even-Odd for determining the interior of filled shapes. In this rule, a point is considered inside a shape if a ray from the point in any direction crosses an odd number of times with the shape's boundary.
func (*Context) SetFillRuleWinding ¶
func (dc *Context) SetFillRuleWinding()
SetFillRuleWinding sets the fill rule to Winding for determining the interior of filled shapes.
This method sets the fill rule to Winding for determining the interior of filled shapes. In this rule, a point is considered inside a shape if a ray from the point in any direction crosses an odd number of times with the shape's boundary.
func (*Context) SetFillStyle ¶
SetFillStyle sets the fill style of the rendering context.
This method allows you to set the fill style of the rendering context using the specified 'pattern'. The 'pattern' can be any implementation of the Pattern interface, such as SolidPattern, Gradient, or TexturePattern. If a SolidPattern is used, the method also updates the current 'color' of the context.
func (*Context) SetFontFace ¶
SetFontFace sets the font face for text rendering.
This method sets the font face for rendering text. The provided `fontFace` is used for subsequent text operations. You can obtain a font face using the `LoadFontFace` or related methods.
func (*Context) SetHexColor ¶
SetHexColor sets the fill and stroke color of the rendering context using a hexadecimal color string.
This method sets both the fill and stroke colors of the rendering context to the colors specified in the hexadecimal color string 'x'. The 'x' parameter should be a string in the format "#RGB" or "#RRGGBB" or "#RRGGBBAA".
func (*Context) SetInterpolator ¶
func (dc *Context) SetInterpolator(interp draw.Interpolator)
SetInterpolator sets the drawing interpolator for the context.
This method allows you to set a custom drawing interpolator for the context. The interpolator is responsible for determining how paths and shapes are transformed and rendered, affecting the quality and smoothness of the output. Providing a nil interpolator will result in a panic.
func (*Context) SetLineCap ¶
SetLineCap sets the line cap style for the end of stroked lines.
This method allows you to set the line cap style for the ends of stroked lines. You can choose from three predefined styles: LineCapRound, LineCapButt, and LineCapSquare.
func (*Context) SetLineCapButt ¶
func (dc *Context) SetLineCapButt()
SetLineCapButt sets the line cap style to Butt for the end of stroked lines.
This method sets the line cap style to Butt for the ends of stroked lines, which results in flat line endings.
func (*Context) SetLineCapRound ¶
func (dc *Context) SetLineCapRound()
SetLineCapRound sets the line cap style to Round for the end of stroked lines.
This method sets the line cap style to Round for the ends of stroked lines, which results in rounded line endings.
func (*Context) SetLineCapSquare ¶
func (dc *Context) SetLineCapSquare()
SetLineCapSquare sets the line cap style to Square for the end of stroked lines.
This method sets the line cap style to Square for the ends of stroked lines, which results in square line endings.
func (*Context) SetLineJoin ¶
SetLineJoin sets the line join style for the intersection of stroked lines.
This method allows you to set the line join style for the intersections of stroked lines. You can choose from two predefined styles: LineJoinRound and LineJoinBevel.
func (*Context) SetLineJoinBevel ¶
func (dc *Context) SetLineJoinBevel()
SetLineJoinBevel sets the line join style to Bevel for the intersection of stroked lines.
This method sets the line join style to Bevel for the intersections of stroked lines, which results in beveled intersections.
func (*Context) SetLineJoinRound ¶
func (dc *Context) SetLineJoinRound()
SetLineJoinRound sets the line join style to Round for the intersection of stroked lines.
This method sets the line join style to Round for the intersections of stroked lines, which results in rounded intersections.
func (*Context) SetLineWidth ¶
SetLineWidth sets the line width for drawing operations.
This method allows you to set the line width for stroking lines and drawing shapes. The 'lineWidth' parameter specifies the width of lines in user space units (typically pixels).
func (*Context) SetMask ¶
SetMask sets the mask of the rendering context.
This method sets the mask of the rendering context to the specified image.Alpha mask. The mask size must match the size of the context's image. If the mask size does not match, an error is returned.
func (*Context) SetPixel ¶
SetPixel sets the color of a single pixel at the specified coordinates.
This method sets the color of a single pixel at the given (x, y) coordinates in the context's image to the current color. It effectively paints a single pixel with the specified color.
func (*Context) SetRGB ¶
SetRGB sets the fill and stroke color of the rendering context to the specified RGB color using floating-point values.
This method sets both the fill and stroke colors of the rendering context to the specified RGB color using floating-point values in the range [0.0, 1.0]. The 'r', 'g', and 'b' parameters should represent the red, green, and blue components, and an alpha value of 1.0 (fully opaque) is used.
func (*Context) SetRGB255 ¶
SetRGB255 sets the fill and stroke color of the rendering context to the specified RGB color using 8-bit values.
This method sets both the fill and stroke colors of the rendering context to the specified RGB color using 8-bit values for red, green, and blue. The 'r', 'g', and 'b' parameters should be integers in the range [0, 255], and an alpha value of 255 (fully opaque) is used.
func (*Context) SetRGBA ¶
SetRGBA sets the fill and stroke color of the rendering context to the specified RGBA color using floating-point values.
This method sets both the fill and stroke colors of the rendering context to the specified RGBA color using floating-point values in the range [0.0, 1.0]. The 'r', 'g', 'b', and 'a' parameters should represent the red, green, blue, and alpha components, respectively.
func (*Context) SetRGBA255 ¶
SetRGBA255 sets the fill and stroke color of the rendering context to the specified RGBA color using 8-bit values.
This method sets both the fill and stroke colors of the rendering context to the specified RGBA color using 8-bit values for red, green, blue, and alpha. The 'r', 'g', 'b', and 'a' parameters should be integers in the range [0, 255].
func (*Context) SetStrokeStyle ¶
SetStrokeStyle sets the stroke style of the rendering context.
This method allows you to set the stroke style of the rendering context using the specified 'pattern'. The 'pattern' can be any implementation of the Pattern interface, such as SolidPattern, Gradient, or TexturePattern.
func (*Context) Shear ¶
Shear applies a shear transformation to the current transformation matrix.
This method shears the drawing context by the specified horizontal (x) and vertical (y) shear factors. It modifies the current transformation matrix to reflect the shear.
func (*Context) ShearAbout ¶
ShearAbout applies a shear transformation about a specified point.
This method shears the drawing context by the specified horizontal (sx) and vertical (sy) shear factors around the point (x, y). It is equivalent to translating the context to the center of shearing, shearing it, and then translating it back to its original position.
func (*Context) Stroke ¶
func (dc *Context) Stroke()
Stroke applies the stroke operation to the current path and clears the path.
This method applies the stroke operation to the current path and clears the path. It uses the StrokePreserve method to render the stroke and then clears the path, making it ready for further path construction.
func (*Context) StrokePreserve ¶
func (dc *Context) StrokePreserve()
StrokePreserve applies the stroke operation to the current path, preserving the path for future rendering.
This method applies the stroke operation to the current path and preserves the path for future rendering. It selects the appropriate painter based on the stroke pattern and the presence of a mask. It then calls the stroke method to render the stroke. After the stroke is applied, the current path remains intact.
func (*Context) TransformPoint ¶
TransformPoint applies the current transformation matrix to the given (x, y) coordinates.
This method transforms the (x, y) coordinates using the current transformation matrix. It returns the transformed coordinates (tx, ty).
func (*Context) Translate ¶
Translate applies a translation to the current transformation matrix.
This method translates the drawing context by the specified horizontal (x) and vertical (y) amounts. It modifies the current transformation matrix to reflect the translation.
func (*Context) Width ¶
Width returns the width of the rendering context.
This method retrieves the width of the rendering context in pixels.
func (*Context) WordWrap ¶
WordWrap wraps a text string to fit within a specified width.
This method takes a text string `s` and wraps it to fit within a given width `w`, breaking it into multiple lines as necessary to prevent text from exceeding the specified width. The result is returned as a slice of strings, each representing a wrapped line of text.
type FillRule ¶
type FillRule int
FillRule specifies the fill rule for determining the interior of complex paths.
type Gradient ¶
type Gradient interface { Pattern // AddColorStop appends a color stop to the linear gradient at the specified offset. // // This method adds a color stop to the gradient with the specified offset and color. Color stops // define where colors change within the gradient. The stops are sorted in ascending order based // on their offset values. AddColorStop(offset float64, color color.Color) }
Gradient is an interface representing a gradient pattern that can be used to fill shapes with smooth color transitions.
func NewConicGradient ¶
NewConicGradient creates a new conic gradient with the specified center coordinates and rotation angle in degrees.
This function creates a conic gradient, which is a type of gradient that varies in color and smoothly rotates around a central point. You can define the center coordinates (cx, cy) and the rotation angle in degrees to control the gradient's appearance.
func NewLinearGradient ¶
NewLinearGradient creates a new linear gradient pattern that spans from point (x0, y0) to point (x1, y1).
This function creates and returns a linear gradient pattern with the specified start and end points. Linear gradients fill an area with colors that transition from one point to another in a straight line.
func NewRadialGradient ¶
NewRadialGradient creates a new radial gradient object based on the specified parameters.
This function initializes a radial gradient with the given circle coordinates and radii, which define the gradient's shape. The radial gradient will interpolate colors smoothly from one circle (defined by x0, y0, r0) to another circle (defined by x1, y1, r1).
type LineCap ¶
type LineCap int
LineCap defines the possible line cap styles for drawing paths in a rendering context.
type LineJoin ¶
type LineJoin int
LineJoin defines the possible line join styles for connecting path segments in a rendering context.
type Matrix ¶
type Matrix struct {
XX, YX, XY, YY, X0, Y0 float64
}
Matrix represents a 2D transformation matrix with six components: XX, YX, XY, YY, X0, and Y0. This matrix is used to transform points, vectors, or perform various geometric transformations.
func Identity ¶
func Identity() Matrix
Identity returns the identity matrix, which has no effect on transformations. The identity matrix is used as a starting point for geometric transformations.
func Rotate ¶
Rotate returns a rotation matrix that rotates points by the specified angle (in radians) in a counterclockwise direction. This matrix is used to rotate objects in a 2D space.
func Scale ¶
Scale returns a scaling matrix that scales points by the specified horizontal and vertical factors (x, y). This matrix is used to resize objects in a 2D space.
func Shear ¶
Shear returns a shear matrix that shears points in the horizontal (x) and vertical (y) directions. This matrix is used to skew or slant objects in a 2D space.
func Translate ¶
Translate returns a translation matrix that moves points by the specified horizontal and vertical offsets (x, y). This matrix is used to shift objects in a 2D space.
func (Matrix) Multiply ¶
Multiply multiplies two matrices, a and b, and returns a new matrix that represents the combined transformation. This operation is used to apply a sequence of matrix transformations to points or objects in a 2D space.
func (Matrix) Rotate ¶
Rotate returns a new matrix resulting from applying a 2D rotation transformation by the given angle to matrix 'a'.
func (Matrix) Scale ¶
Scale returns a new matrix resulting from applying a 2D scaling transformation to matrix 'a'.
func (Matrix) Shear ¶
Shear returns a new matrix resulting from applying a 2D shear transformation by the given factors to matrix 'a'.
func (Matrix) TransformPoint ¶
TransformPoint applies the matrix transformation represented by 'a' to a 2D point (x, y). It returns the transformed point (tx, ty) after applying the matrix transformation.
func (Matrix) TransformVector ¶
TransformVector applies the matrix transformation represented by 'a' to a 2D vector (x, y). It returns the transformed vector (tx, ty) after applying the matrix transformation.
type Pattern ¶
Pattern is an interface representing a pattern used for filling areas with a repeating design. Implementations of this interface must provide the ability to sample and retrieve color information at specific coordinates (x, y) within the pattern.
func NewSolidPattern ¶
NewSolidPattern creates and returns a solid color pattern using the specified color.
type Point ¶
type Point struct {
X, Y float64
}
Point represents a two-dimensional point with X and Y coordinates.
func CubicBezier ¶
CubicBezier computes a series of points on a cubic Bézier curve defined by four control points.
The cubic Bézier curve is determined by the starting point (x0, y0), two control points (x1, y1) and (x2, y2), and the ending point (x3, y3). The function calculates 'n' equidistant points along the curve, where 'n' is determined by the cumulative length of the curve. If the calculated number of points is less than 4, it defaults to 4 points.
func QuadraticBezier ¶
QuadraticBezier computes a series of points on a quadratic Bézier curve defined by three control points.
The quadratic Bézier curve is determined by the starting point (x0, y0), a control point (x1, y1), and the ending point (x2, y2). The function calculates 'n' equidistant points along the curve, where 'n' is determined by the curve's total length. If the calculated number of points is less than 4, it defaults to 4 points.
type RepeatOp ¶
type RepeatOp int
RepeatOp specifies how an image is repeated or tiled when it is painted onto a larger canvas.
const ( RepeatBoth RepeatOp = iota // Repeat both indicates that the image is repeated both horizontally (X-axis) and vertically (Y-axis). RepeatX // Repeat x indicates that the image is repeated horizontally (X-axis) but not vertically (Y-axis). RepeatY // Repeat y indicates that the image is repeated vertically (Y-axis) but not horizontally (X-axis). RepeatNone // Repeat none indicates that the image is not repeated and is displayed only once. )