imagex

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2024 License: BSD-3-Clause Imports: 21 Imported by: 13

Documentation

Index

Constants

This section is empty.

Variables

View Source
var UpdateTestImages = updateTestImages

UpdateTestImages indicates whether to update currently saved test images in [AssertImage] instead of comparing against them. It is automatically set if the build tag "update" is specified, and it should typically only be set through that. It should only be set when behavior has been updated that causes test images to change, and it should only be set once and then turned back off.

Functions

func Assert

func Assert(t TestingT, img image.Image, filename string)

Assert asserts that the given image is equivalent to the image stored at the given filename in the testdata directory, with ".png" added to the filename if there is no extension (eg: "button" becomes "testdata/button.png"). Forward slashes are automatically replaced with backslashes on Windows. If it is not, it fails the test with an error, but continues its execution. If there is no image at the given filename in the testdata directory, it creates the image.

func Base64SplitLines

func Base64SplitLines(b []byte) []byte

Base64SplitLines splits the encoded Base64 bytes into standard lines of 76 chars each. The last line also ends in a newline

func CloneAsRGBA

func CloneAsRGBA(src image.Image) *image.RGBA

CloneAsRGBA returns an RGBA copy of the supplied image.

func CompareColors

func CompareColors(cc, ic color.RGBA, tol int) bool

CompareColors returns true if two colors are more different than tol

func CompareUint8

func CompareUint8(cc, ic uint8, tol int) bool

CompareUint8 returns true if two numbers are more different than tol

func FromBase64

func FromBase64(fmt string, eb []byte) (image.Image, error)

FromBase64 returns image from Base64-encoded bytes in either PNG or JPEG format based on fmt which must end in either png, jpg, or jpeg

func FromBase64JPG

func FromBase64JPG(eb []byte) (image.Image, error)

FromBase64JPG returns image from Base64-encoded bytes in PNG format

func FromBase64PNG

func FromBase64PNG(eb []byte) (image.Image, error)

FromBase64PNG returns image from Base64-encoded bytes in PNG format

func Save

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

Save saves the image to the given filename, with the format inferred from the filename. png, jpeg, gif, tiff, and bmp are supported.

func ToBase64JPG

func ToBase64JPG(img image.Image) ([]byte, string)

ToBase64JPG returns bytes image encoded as a JPG in Base64 format with "image/jpeg" mimetype returned

func ToBase64PNG

func ToBase64PNG(img image.Image) ([]byte, string)

ToBase64PNG returns bytes of image encoded as a PNG in Base64 format with "image/png" mimetype returned

func Write

func Write(im image.Image, w io.Writer, f Formats) error

Write writes the image to the given writer using the given foramt. png, jpeg, gif, tiff, and bmp are supported.

Types

type Formats

type Formats int32 //enums:enum

Formats are the supported image encoding / decoding formats

const (
	None Formats = iota
	PNG
	JPEG
	GIF
	TIFF
	BMP
	WebP
)

The supported image encoding formats

const FormatsN Formats = 7

FormatsN is the highest valid value for type Formats, plus one.

func ExtToFormat

func ExtToFormat(ext string) (Formats, error)

ExtToFormat returns a Format based on a filename extension, which can start with a . or not

func FormatsValues

func FormatsValues() []Formats

FormatsValues returns all possible values for the type Formats.

func Open

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

Open opens an image from the given filename. The format is inferred automatically, and is returned using the Formats enum. png, jpeg, gif, tiff, bmp, and webp are supported.

func OpenFS

func OpenFS(fsys fs.FS, filename string) (image.Image, Formats, error)

OpenFS opens an image from the given filename using the given fs.FS filesystem (e.g., for embed files). The format is inferred automatically, and is returned using the Formats enum. png, jpeg, gif, tiff, bmp, and webp are supported.

func Read

func Read(r io.Reader) (image.Image, Formats, error)

Read reads an image to the given reader, The format is inferred automatically, and is returned using the Formats enum. png, jpeg, gif, tiff, bmp, and webp are supported.

func (Formats) Desc

func (i Formats) Desc() string

Desc returns the description of the Formats value.

func (Formats) Int64

func (i Formats) Int64() int64

Int64 returns the Formats value as an int64.

func (Formats) MarshalText

func (i Formats) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*Formats) SetInt64

func (i *Formats) SetInt64(in int64)

SetInt64 sets the Formats value from an int64.

func (*Formats) SetString

func (i *Formats) SetString(s string) error

SetString sets the Formats value from its string representation, and returns an error if the string is invalid.

func (Formats) String

func (i Formats) String() string

String returns the string representation of this Formats value.

func (*Formats) UnmarshalText

func (i *Formats) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (Formats) Values

func (i Formats) Values() []enums.Enum

Values returns all possible values for the type Formats.

type TestingT

type TestingT interface {
	Errorf(format string, args ...any)
}

TestingT is an interface wrapper around *testing.T

Jump to

Keyboard shortcuts

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