thumbnails

package module
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultThumbnailPath

func DefaultThumbnailPath(docPath string, width uint) string

DefaultThumbnailPath returns the conventional thumbnail path for a document. e.g. "doc.pdf" -> "doc.tn_64.png"

func ErrorPlaceholder

func ErrorPlaceholder(label string, width uint) image.Image

ErrorPlaceholder generates a coloured placeholder image with the given label. The image is width × pageHeight(width) with white centred text.

func Generate

func Generate(filePath string, width uint) (image.Image, error)

Generate reads a file from disk and returns a composite-style thumbnail. Width is the desired thumbnail width in pixels; height is width × √2 (A4 ratio). Supported formats: PDF, TIFF (multi-page composite), JPG, PNG (simple resize).

func GenerateAndSave

func GenerateAndSave(filePath, outputPath string, width uint) error

GenerateAndSave generates a composite-style thumbnail and saves it as PNG to outputPath.

func GenerateOrPlaceholder

func GenerateOrPlaceholder(filePath string, width uint) image.Image

GenerateOrPlaceholder wraps Generate: on success it returns the real thumbnail; on any error it returns a placeholder image indicating the error type. It never returns nil.

func GenerateStyled

func GenerateStyled(filePath string, width uint, style Style) (image.Image, error)

GenerateStyled reads a file and returns a thumbnail in the given style.

func GenerateStyledAndSave

func GenerateStyledAndSave(filePath, outputPath string, width uint, style Style) error

GenerateStyledAndSave generates a styled thumbnail and saves it as PNG to outputPath.

Types

type CorruptionResult

type CorruptionResult struct {
	// Corrupt is true if the image appears corrupted.
	Corrupt bool
	// Reason describes the type of corruption detected.
	Reason string
	// CorruptRowFraction is the fraction of rows with non-grayscale artifacts (0.0–1.0).
	CorruptRowFraction float64
	// NonOpaqueRowFraction is the fraction of rows containing non-opaque (alpha != 255) pixels.
	NonOpaqueRowFraction float64
}

CorruptionResult describes corruption detected in a rendered page.

func CheckPageCorruption

func CheckPageCorruption(img image.Image) CorruptionResult

CheckPageCorruption detects rendering corruption in a single page image.

PDFium can produce corrupt RGBA buffers where pixel data contains garbage bytes with non-255 alpha values and spurious colour in what should be grayscale or clean colour content. The key signal is rows where a high fraction of pixels have alpha != 255 — legitimate document renders are fully opaque.

func CheckThumbnailCorruption

func CheckThumbnailCorruption(img image.Image) CorruptionResult

CheckThumbnailCorruption checks a final composited thumbnail for corruption. This catches issues that survive resizing/compositing.

type Style

type Style int

Style controls the thumbnail rendering mode.

const (
	// StyleComposite renders multi-page documents as side-by-side page tiles
	// with a "+" indicator for documents with more than 4 pages.
	StyleComposite Style = iota
	// StyleUniform renders all documents as a fixed width × 1.42×width thumbnail
	// with a page-count watermark for multi-page documents.
	StyleUniform
)

Directories

Path Synopsis
cmd
batch command
diagnose command
gentestimages command
Command gentestimages creates PNG and JPEG test images in testdata/.
Command gentestimages creates PNG and JPEG test images in testdata/.
showcase command
Command showcase generates sample thumbnails into a temporary directory so you can visually inspect the output of every supported path.
Command showcase generates sample thumbnails into a temporary directory so you can visually inspect the output of every supported path.

Jump to

Keyboard shortcuts

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