image

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2025 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dict added in v0.6.0

type Dict struct {
	// Width is the width of the image in pixels.
	Width int

	// Height is the height of the image in pixels.
	Height int

	// ColorSpace is the color space in which image samples are specified.
	// It can be any type of color space except Pattern.
	ColorSpace color.Space

	// BitsPerComponent is the number of bits used to represent each color component.
	// The value must be 1, 2, 4, 8, or (from PDF 1.5) 16.
	BitsPerComponent int

	// Intent (optional) is the name of a color rendering intent to be used in rendering the image.
	Intent graphics.RenderingIntent

	// MaskImage (optional) determines which parts of the image are to be
	// painted.
	//
	// Only one of MaskImage or MaskColors may be specified.
	MaskImage *ImageMask

	// MaskColors (optional) is an array of colors used for color key masking.
	// When specified, image samples with colors falling within the defined ranges
	// will not be painted, allowing the background to show through (similar to
	// chroma-key/green screen effects).
	//
	// The array contains pairs of min/max values for each color component:
	// [min1, max1, min2, max2, ..., minN, maxN] where N is the number of color
	// components in the image's color space. Each value must be in the range
	// 0 to (2^BitsPerComponent - 1) and represents raw color values before
	// any Decode array processing.
	//
	// A pixel is masked if ALL of its color components fall within their
	// respective min/max ranges.
	//
	// Only one of MaskImage or MaskColors may be specified.
	MaskColors []uint16

	// Decode (optional) is an array of numbers describing how to map image
	// samples into the range of values appropriate for the image's color
	// space. The slice must have twice the number of color components
	// required by ColorSpace.
	Decode []float64

	// Interpolate indicates whether image interpolation should be performed by
	// a PDF processor.
	Interpolate bool

	// Alternates (optional) is an array of alternate image dictionaries for this image.
	Alternates []*Dict

	// Name is deprecated and should be left empty.
	// Only used in PDF 1.0 where it was the name used to reference the image
	// mask from within content streams.
	Name pdf.Name

	// Metadata (optional) is a metadata stream containing metadata for the image.
	Metadata *metadata.Stream

	// WriteData is a function that writes the image data to the provided writer.
	// The data should be written row by row, with each row containing
	// Width * ColorSpace.Channels() samples, each sample using BitsPerComponent bits.
	WriteData func(io.Writer) error
}

func FromImage added in v0.6.0

func FromImage(img image.Image, colorSpace color.Space, bitsPerComponent int) *Dict

FromImage creates a Dict from an image.Image. The ColorSpace and BitsPerComponent must be set appropriately for the image.

func FromImageWithMask added in v0.6.0

func FromImageWithMask(img image.Image, mask image.Image, colorSpace color.Space, bitsPerComponent int) *Dict

FromImageWithMask creates a Dict with an associated ImageMask from two image.Image objects.

func (*Dict) Bounds added in v0.6.0

func (d *Dict) Bounds() Rectangle

Bounds returns the dimensions of the image.

func (*Dict) Embed added in v0.6.0

func (d *Dict) Embed(rm *pdf.ResourceManager) (pdf.Native, pdf.Unused, error)

func (*Dict) Subtype added in v0.6.0

func (d *Dict) Subtype() pdf.Name

Subtype returns the PDF XObject subtype for images.

type Image

type Image interface {
	Bounds() Rectangle
	Subtype() pdf.Name
	pdf.Embedder[pdf.Unused]
}

Image represents a raster image which can be embedded in a PDF file.

func JPEG

func JPEG(src image.Image, opts *jpeg.Options) (Image, error)

JPEG creates a new PDF image from a JPEG image. The file is stored in the DCTDecode format in the PDF file.

type ImageMask added in v0.6.0

type ImageMask struct {
	// Width is the width of the image mask in pixels.
	Width int

	// Height is the height of the image mask in pixels.
	Height int

	// WriteData is a function that writes the mask data to the provided writer.
	// The data should be written as a continuous bit stream, with each row
	// starting at a new byte boundary. 0 = opaque, 1 = transparent.
	WriteData func(io.Writer) error

	// Interpolate enables edge smoothing for the mask to reduce jagged
	// appearance in low-resolution stencil masks.
	Interpolate bool

	// Alternates (optional) is an array of alternate image dictionaries for this image.
	Alternates []*ImageMask

	// Name is deprecated and should be left empty.
	// Only used in PDF 1.0 where it was the name used to reference the image
	// from within content streams.
	Name pdf.Name

	// Metadata (optional) is a metadata stream containing metadata for the image.
	Metadata *metadata.Stream
}

func FromImageMask added in v0.6.0

func FromImageMask(img image.Image) *ImageMask

FromImageMask creates an ImageMask from an image.Image. Only the alpha channel is used, with alpha values rounded to full opacity or full transparency.

func (*ImageMask) Bounds added in v0.6.0

func (m *ImageMask) Bounds() Rectangle

func (*ImageMask) Embed added in v0.6.0

func (m *ImageMask) Embed(rm *pdf.ResourceManager) (pdf.Native, pdf.Unused, error)

func (*ImageMask) Subtype added in v0.6.0

func (m *ImageMask) Subtype() pdf.Name

type Indexed added in v0.6.0

type Indexed struct {
	Pix        []uint8
	Width      int
	Height     int
	ColorSpace color.Space
}

Indexed represents an image with an indexed color space.

func NewIndexed added in v0.6.0

func NewIndexed(width, height int, cs color.Space) *Indexed

NewIndexed returns a new Indexed image of the given size.

func (*Indexed) Bounds added in v0.6.0

func (im *Indexed) Bounds() Rectangle

Bounds returns the image bounds. This implements the Image interface.

func (*Indexed) Embed added in v0.6.0

func (im *Indexed) Embed(rm *pdf.ResourceManager) (pdf.Native, pdf.Unused, error)

Embed adds the image to the PDF file. This implements the Image interface.

func (*Indexed) Subtype added in v0.6.0

func (im *Indexed) Subtype() pdf.Name

Subtype returns /Image. This implements the Image interface.

type PNG

type PNG struct {
	Data image.Image

	// ColorSpace is the color space of the image.
	// If this is not set, the image will be embedded as a DeviceRGB image.
	ColorSpace color.Space
}

PNG represents an image which is stored losslessly in the PDF file. The encoding is similar to the PNG format.

func (*PNG) Bounds added in v0.6.0

func (im *PNG) Bounds() Rectangle

Bounds implements the Image interface.

func (*PNG) Embed added in v0.6.0

func (im *PNG) Embed(rm *pdf.ResourceManager) (pdf.Native, pdf.Unused, error)

Embed ensures that the image is embedded in the PDF file. This implements the Image interface.

func (*PNG) Subtype added in v0.6.0

func (im *PNG) Subtype() pdf.Name

Subtype returns /Image. This implements the Image interface.

type PixelRow added in v0.6.0

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

PixelRow is a helper for efficiently packing pixel data into bytes for PDF image streams. It handles arbitrary bits per pixel and packs them into a byte array.

func NewPixelRow added in v0.6.0

func NewPixelRow(numElems, bitsPerElem int) *PixelRow

NewPixelRow creates a new PixelRow for packing image data. numElems is the number of elements (pixels * channels) in the row. bitsPerElem is the number of bits per element (1, 2, 4, 8, or 16).

func (*PixelRow) AppendBits added in v0.6.0

func (r *PixelRow) AppendBits(bits uint16)

AppendBits appends the specified number of bits to the row. Only the low-order numBits bits of the value are used.

func (*PixelRow) Bytes added in v0.6.0

func (r *PixelRow) Bytes() []byte

Bytes returns the underlying byte slice containing the packed pixel data.

func (*PixelRow) Reset added in v0.6.0

func (r *PixelRow) Reset()

Reset clears the row buffer and resets position counters.

type Rectangle

type Rectangle struct {
	XMin, YMin, XMax, YMax int
}

Rectangle gives the dimensions of an image.

func (Rectangle) Dx

func (r Rectangle) Dx() int

Dx returns the width of the rectangle.

func (Rectangle) Dy

func (r Rectangle) Dy() int

Dy returns the height of the rectangle.

Jump to

Keyboard shortcuts

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