imagediff

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package imagediff compares rendered images and produces deterministic visual diagnostics suitable for test failures.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DimensionMismatchError

type DimensionMismatchError struct {
	Expected image.Point
	Actual   image.Point
}

DimensionMismatchError reports images whose pixel dimensions differ.

func (*DimensionMismatchError) Error

func (e *DimensionMismatchError) Error() string

type Metrics

type Metrics struct {
	// Width and Height are the comparison-canvas dimensions. ExpectedWidth,
	// ExpectedHeight, ActualWidth, and ActualHeight retain the source sizes so a
	// crop regression still produces a useful report instead of a nil Result.
	Width          int
	Height         int
	ExpectedWidth  int
	ExpectedHeight int
	ActualWidth    int
	ActualHeight   int

	ChangedPixels   int
	MaxChannelDelta int
	RMSE            float64
}

Metrics describes the pixel differences between two equal-sized images. RMSE is calculated across all four non-premultiplied RGBA channels.

type MismatchError

type MismatchError struct {
	Metrics   Metrics
	Tolerance Tolerance
}

MismatchError reports a comparison that exceeded at least one tolerance. Compare still returns a complete Result alongside this error.

func (*MismatchError) Error

func (e *MismatchError) Error() string

type Options

type Options struct {
	Tolerance    Tolerance
	ExpectedName string
	ActualName   string
}

Options controls a comparison and the labels in its HTML report.

type Result

type Result struct {
	Metrics   Metrics
	Tolerance Tolerance
	Passed    bool

	ExpectedPNG []byte
	ActualPNG   []byte
	OverlayPNG  []byte
	HeatmapPNG  []byte
	ReportHTML  []byte
}

Result contains normalized PNG artifacts and a self-contained HTML report. The report embeds all four PNGs as data URLs and has no external resources.

func Compare

func Compare(expected, actual []byte, opts Options) (*Result, error)

Compare decodes two encoded images, compares them, and creates diagnostics. PNG, JPEG, and GIF inputs are registered by this package.

func CompareImages

func CompareImages(expected, actual image.Image, opts Options) (*Result, error)

CompareImages compares two decoded images and creates diagnostics. Image bounds may have different origins, but their dimensions must match exactly.

func (*Result) WriteReport

func (r *Result) WriteReport(path string) error

WriteReport writes the self-contained HTML report, creating parent directories as needed.

type Tolerance

type Tolerance struct {
	MaxChangedPixels int
	MaxChannelDelta  int
	MaxRMSE          float64
}

Tolerance contains the inclusive limits for a passing comparison. Its zero value requires an exact pixel match.

Jump to

Keyboard shortcuts

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