Help us shape the future of Go! Take the 2026 Go Developer Survey

tiff

package module
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: BSD-3-Clause Imports: 15 Imported by: 85

README

Note

This package is an improved version of x/image/tiff featuring:

  • Read support for CCITT Group3/4 compressed images using x/image/ccitt
  • Read/write support for LZW compressed images.
  • Read/write support for the CMYK color model.
  • Read support for JPEG compressed images.
  • Read support for multi page TIFF files.

Background

Working on pdfcpu (a PDF processor) created a need for processing TIFF files and LZW compression.

  1. CCITT compression for monochrome images was the first need. This is being addressed as part of ongoing work on x/image/ccitt.

  2. TIFF LZW compression uses MSB bit order, 8-bit literal codes, and TIFF's code-width transition behavior.

  3. The PDF specification defines a CMYK color space. This is currently not supported at x/image/tiff.

Goal

An improved version of x/image/tiff with full read/write support for CCITT, LZW, JPEG compression and the CMYK color model.

Documentation

Overview

Package tiff is an enhanced version of x/image/tiff.

It adds support for LZW compression and the CMYK color model.

More information: https://github.com/hhrutter/tiff

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(r io.Reader) (img image.Image, err error)

Decode reads a TIFF image from r and returns it as an image.Image. The type of Image returned depends on the contents of the TIFF.

func DecodeAt added in v1.0.2

func DecodeAt(r io.Reader, ifdOffset int64) (img image.Image, err error)

DecodeAt reads a TIFF image from r at ifdOffset and returns it as an image.Image. The type of Image returned depends on the contents of the TIFF.

func DecodeConfig

func DecodeConfig(r io.Reader) (image.Config, error)

DecodeConfig returns the color model and dimensions of a TIFF image without decoding the entire image.

func DecodeConfigAt added in v1.0.2

func DecodeConfigAt(r io.Reader, ifdOffset int64) (image.Config, error)

DecodeConfig returns the color model and dimensions of a TIFF image at ifdOffset without decoding the entire image.

func Encode

func Encode(w io.Writer, m image.Image, opt *Options) error

Encode writes the image m to w. opt determines the options used for encoding, such as the compression type. If opt is nil, an uncompressed image is written.

func EncodeAll added in v1.0.4

func EncodeAll(w io.Writer, m []image.Image, opt *Options) error

EncodeAll writes the images in m to w as a multi-page TIFF. opt determines the options used for encoding each image, such as the compression type. If opt is nil, uncompressed images are written.

Types

type CompressionType

type CompressionType int

CompressionType describes the type of compression used in Options.

const (
	Uncompressed CompressionType = iota
	Deflate
	LZW
	CCITTGroup3
	CCITTGroup4
	JPEGOld
	JPEG
)

Constants for supported compression types.

type FormatError

type FormatError string

A FormatError reports that the input is not a valid TIFF image.

func (FormatError) Error

func (e FormatError) Error() string

type Options

type Options struct {
	// Compression is the type of compression used.
	Compression CompressionType
	// Predictor determines whether a differencing predictor is used;
	// if true, instead of each pixel's color, the color difference to the
	// preceding one is saved.  This improves the compression for certain
	// types of images and compressors. For example, it works well for
	// photos with Deflate compression.
	Predictor bool
}

Options are the encoding parameters.

type UnsupportedError

type UnsupportedError string

An UnsupportedError reports that the input uses a valid but unimplemented feature.

func (UnsupportedError) Error

func (e UnsupportedError) Error() string

Jump to

Keyboard shortcuts

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