pngutil

package module
v0.0.0-...-5e2cf50 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package pngutil provides a simple way to handle some common tasks with PNGs such as replacing metadata and checking magic bytes.

Index

Constants

View Source
const (
	MetaTitle        = "Title"         // Short (one line) title or caption for image
	MetaAuthor       = "Author"        // Name of image's creator
	MetaDescription  = "Description"   // Description of image (possibly long)
	MetaCopyright    = "Copyright"     // Copyright notice
	MetaCreationTime = "Creation Time" // Time of original image creation
	MetaSoftware     = "Software"      // Software used to create the image
	MetaDisclaimer   = "Disclaimer"    // Legal disclaimer
	MetaWarning      = "Warning"       // Warning of nature of content
	MetaSource       = "Source"        // Device used to create the image
	MetaComment      = "Comment"       // Miscellaneous comment
)

Predefined metadata keywords in the PNG specification: https://www.w3.org/TR/PNG/#11keywords

Variables

This section is empty.

Functions

func Assert

func Assert(rs io.ReadSeeker) (err error)

Assert returns an error if r doesn't represent a valid PNG image. It checks for the header, the first 8 bytes of the IHDR chunk, and the IEND chunk without reading the entire file.

The current offset of rs is restored after Assert has completed its checks.

func ReplaceMeta

func ReplaceMeta(f io.ReadSeeker, metadata Metadata) (mrs *multiReadSeeker, err error)

ReplaceMeta takes a PNG file represented by f and returns a readseeker mrs which is the same file with only the supplied metadata. The resulting image represented by mrs is not altered.

A zero-length metadata will result in mrs having no metadata at all.

ReplaceMeta calls Assert and will error under the same conditions. It is unnecessary for callers to call Assert if they intend to immediately follow with ReplaceMeta.

Since mrs is a wrapper around the new metadata and f, altering f will affect mrs. Therefore callers are recommended to drain mrs before altering f.

The metadata is assigned to an iTXt chunk at the start of the file.

func WriteFile

func WriteFile(name string, r io.Reader) (n int64, err error)

WriteFile drains r and writes it to a new file at name, returning the number of bytes it wrote and an error, if any.

If name doesn't already end in ".png" WriteFile will add it to the end.

Types

type Metadata

type Metadata map[string]string

Jump to

Keyboard shortcuts

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