pngmeta

package
v0.35.2 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package pngmeta provides support for working with embedded PNG metadata.

Index

Examples

Constants

This section is empty.

Variables

View Source
var Format = meta.ImageFormat("PNG")

Format specifies the image format handled by this package

Functions

func Load

func Load(r io.Reader) (md *meta.Data, imgStream io.Reader, err error)

Load loads the metadata for a PNG image stream.

Only as much of the stream is consumed as necessary to extract the metadata; the returned stream contains a buffered copy of the consumed data such that reading from it will produce the same results as fully reading the input stream. This provides a convenient way to load the full image after loading the metadata.

An error is returned if basic metadata could not be extracted. The returned stream still provides the full image data.

Example (BasicPNGMetadata)
package main

import (
	"fmt"
	"github.com/mandykoh/prism/meta"
	"github.com/mandykoh/prism/meta/pngmeta"
	"image"
	"image/png"
	"os"
)

func printMetadata(md *meta.Data, img image.Image) {
	fmt.Printf("Format: %s\n", md.Format)
	fmt.Printf("BitsPerComponent: %d\n", md.BitsPerComponent)
	fmt.Printf("PixelHeight: %d\n", md.PixelHeight)
	fmt.Printf("PixelWidth: %d\n", md.PixelWidth)

	fmt.Printf("Actual image height: %d\n", img.Bounds().Dy())
	fmt.Printf("Actual image width: %d\n", img.Bounds().Dx())
}

func main() {
	inFile, err := os.Open("../../test-images/pizza-rgb8-srgb.png")
	if err != nil {
		panic(err)
	}
	defer inFile.Close()

	md, imgStream, err := pngmeta.Load(inFile)
	if err != nil {
		panic(err)
	}

	img, err := png.Decode(imgStream)
	if err != nil {
		panic(err)
	}

	printMetadata(md, img)

}
Output:

Format: PNG
BitsPerComponent: 8
PixelHeight: 1200
PixelWidth: 1200
Actual image height: 1200
Actual image width: 1200
Example (EmbeddedICCv4)
package main

import (
	"fmt"
	"github.com/mandykoh/prism/meta"
	"github.com/mandykoh/prism/meta/pngmeta"
	"image/png"
	"os"
)

func printICCProfile(md *meta.Data) {
	profile, err := md.ICCProfile()
	if err != nil {
		panic(err)
	}

	fmt.Printf("ProfileSize: %d\n", profile.Header.ProfileSize)
	fmt.Printf("PreferredCMM: %v\n", profile.Header.PreferredCMM)
	fmt.Printf("ProfileVersion: %s\n", profile.Header.Version)
	fmt.Printf("DeviceClass: %s\n", profile.Header.DeviceClass)
	fmt.Printf("DataColorSpace: %s\n", profile.Header.DataColorSpace)
	fmt.Printf("PCS: %s\n", profile.Header.ProfileConnectionSpace)
	fmt.Printf("CreatedAt: %v\n", profile.Header.CreatedAt)
	fmt.Printf("PrimaryPlatform: %v\n", profile.Header.PrimaryPlatform)
	fmt.Printf("Embedded: %v\n", profile.Header.Embedded)
	fmt.Printf("DependsOnEmbeddedData: %v\n", profile.Header.DependsOnEmbeddedData)
	fmt.Printf("DeviceManufacturer: %s\n", profile.Header.DeviceManufacturer)
	fmt.Printf("DeviceModel: %s\n", profile.Header.DeviceModel)
	fmt.Printf("DeviceAttributes: %064b\n", profile.Header.DeviceAttributes)
	fmt.Printf("RenderingIntent: %v\n", profile.Header.RenderingIntent)
	fmt.Printf("PCSIlluminant: %v\n", profile.Header.PCSIlluminant)
	fmt.Printf("ProfileCreator: %v\n", profile.Header.ProfileCreator)
	fmt.Printf("ProfileID: %0x\n", profile.Header.ProfileID)

	if desc, err := profile.Description(); err != nil {
		panic(err)
	} else {
		fmt.Printf("Description: %s\n", desc)
	}
}

func main() {
	inFile, err := os.Open("../../test-images/pizza-rgb8-srgb.png")
	if err != nil {
		panic(err)
	}
	defer inFile.Close()

	md, imgStream, err := pngmeta.Load(inFile)
	if err != nil {
		panic(err)
	}

	_, err = png.Decode(imgStream)
	if err != nil {
		panic(err)
	}

	printICCProfile(md)

}
Output:

ProfileSize: 596
PreferredCMM: 'lcms'
ProfileVersion: 4.3.0
DeviceClass: Display
DataColorSpace: RGB
PCS: XYZ
CreatedAt: 2020-08-12 21:45:21 +0000 UTC
PrimaryPlatform: Apple Computer, Inc.
Embedded: false
DependsOnEmbeddedData: false
DeviceManufacturer: '    '
DeviceModel: '    '
DeviceAttributes: 0000000000000000000000000000000000000000000000000000000000000000
RenderingIntent: Perceptual
PCSIlluminant: [63190 65536 54061]
ProfileCreator: 'lcms'
ProfileID: 00000000000000000000000000000000
Description: sRGB IEC61966-2.1

Types

This section is empty.

Jump to

Keyboard shortcuts

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