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 ¶
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.