jpegxl

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2026 License: MIT Imports: 21 Imported by: 11

README

jpegxl

Status Go Reference

Go encoder/decoder for JPEG XL Image File Format with support for animated JXL images (decode only).

Based on libjxl compiled to WASM and used with wazero runtime (CGo-free).

The library will first try to use a dynamic/shared library (if installed) via purego and will fall back to WASM.

Build tags

  • nodynamic - do not use dynamic/shared library (use only WASM)
  • wasm2go - transpile WASM to Go instead of using wazero; decodes with jxl-rs and encodes losslessly with zune-jpegxl

Documentation

Overview

Package jpegxl implements an JPEG XL image decoder based on libjxl compiled to WASM.

Index

Constants

View Source
const DefaultEffort = 7

DefaultEffort is the default effort encoding parameter.

View Source
const DefaultQuality = 75

DefaultQuality is the default quality encoding parameter.

Variables

View Source
var (
	ErrMemRead  = errors.New("jpegxl: mem read failed")
	ErrMemWrite = errors.New("jpegxl: mem write failed")
	ErrDecode   = errors.New("jpegxl: decode failed")
	ErrEncode   = errors.New("jpegxl: encode failed")
)

Errors .

View Source
var ErrNoExif = errors.New("jpegxl: no exif data")

ErrNoExif is returned by DecodeExif when the JPEG XL has no Exif box.

Functions

func Decode

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

Decode reads a JPEG XL image from r and returns it as an image.Image.

func DecodeConfig

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

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

func Dynamic added in v0.2.1

func Dynamic() error

Dynamic returns error (if there was any) during opening dynamic/shared library.

func Encode added in v0.2.4

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

Encode writes the image m to w with the given options.

func InitDecoder added in v0.4.1

func InitDecoder()

InitDecoder initializes wazero runtime and compiles the module. This function does nothing if a dynamic/shared library is used and Dynamic() returns nil. There is no need to explicitly call this function, first Decode will initialize the runtime.

func InitEncoder added in v0.4.1

func InitEncoder()

InitEncoder initializes wazero runtime and compiles the module. This function does nothing if a dynamic/shared library is used and Dynamic() returns nil. There is no need to explicitly call this function, first Encode will initialize the runtime.

Types

type Exif added in v0.5.3

type Exif struct {
	// Basic image info
	Orientation int // EXIF orientation (1-8). 1 = normal, values 2-8 indicate rotation/flip.
	Width       int // Image width in pixels.
	Height      int // Image height in pixels.

	// Camera info
	Make     string // Camera manufacturer (e.g., "Canon").
	Model    string // Camera model (e.g., "Canon EOS 5D Mark III").
	Software string // Software used to process/create the image.

	// Date/Time (format: "YYYY:MM:DD HH:MM:SS")
	DateTime         string // File modification date/time.
	DateTimeOriginal string // Original capture date/time (when photo was taken).

	// Exposure settings
	ExposureTime float64 // Shutter speed in seconds (e.g., 0.004 = 1/250s).
	FNumber      float64 // Aperture f-number (e.g., 5.6 = f/5.6).
	ISOSpeed     int     // ISO speed rating (e.g., 800).
	FocalLength  float64 // Lens focal length in millimeters.
	Flash        int     // Flash mode/status (0 = no flash, non-zero = flash fired).

	// GPS location
	GPSLatitude  float64 // Latitude in decimal degrees (positive = North, negative = South).
	GPSLongitude float64 // Longitude in decimal degrees (positive = East, negative = West).
	GPSAltitude  float64 // Altitude in meters above sea level.

	// Copyright/Author
	Copyright string // Copyright notice.
	Artist    string // Creator/photographer name.
}

Exif holds the EXIF metadata decoded from a JPEG XL image.

func DecodeExif added in v0.5.3

func DecodeExif(r io.Reader) (*Exif, error)

DecodeExif reads the EXIF metadata from a JPEG XL image. It returns ErrNoExif if the image carries no Exif box.

type JXL added in v0.1.4

type JXL struct {
	// Decoded images, NRGBA or NRGBA64.
	Image []image.Image
	// Delay times, one per frame, in seconds of a tick.
	Delay []int
}

JXL represents the possibly multiple images stored in a JXL file.

func DecodeAll added in v0.1.3

func DecodeAll(r io.Reader) (*JXL, error)

DecodeAll reads a JPEG XL image from r and returns the sequential frames and timing information.

type Options added in v0.2.4

type Options struct {
	// Quality in the range [0,100]. Default is 75.
	Quality int
	// Effort in the range [1,10]. Sets encoder effort/speed level without affecting decoding speed. Default is 7.
	Effort int
	// Lossless enables lossless compression. Lossless ignores quality.
	Lossless bool
}

Options are the encoding parameters.

Jump to

Keyboard shortcuts

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