Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoJPEG = errors.New("not a JPEG file") ErrNoEXIF = errors.New("no EXIF data found") ErrUnsupported = errors.New("unsupported format") ErrOutOfMemory = errors.New("out of memory") ErrInternal = errors.New("internal error") ErrSyntax = errors.New("syntax error") ErrMissingHuffmanCode = errors.New("missing Huffman code") )
Standard error types for JPEG decoding.
Functions ¶
func Decode ¶
Decode reads a JPEG image from r and returns it as an image.Image. It accepts an optional Options struct to control decoding parameters.
Types ¶
type Exif ¶ added in v0.3.0
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 (may differ from actual JPEG dimensions if rotated).
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 contains metadata extracted from a JPEG image's EXIF data.
func DecodeExif ¶ added in v0.3.0
DecodeExif reads EXIF metadata from a JPEG image without decoding the entire image. It returns an Exif struct containing common EXIF tags like camera make/model, exposure settings, GPS location, and date/time information.
Returns an error if:
- The input is not a valid JPEG
- No EXIF data is present in the image
- EXIF data is corrupted or cannot be parsed
Individual fields in the returned Exif struct may be zero/empty if those specific tags are not present in the EXIF data.
type Options ¶
type Options struct {
// ToRGBA forces the output image to be in the RGBA color space.
// If false, the image will be returned in its native color space,
// which is typically YCbCr for color images or Grayscale for monochrome images.
ToRGBA bool
// UpsampleMethod defines the algorithm used for chroma upsampling when
// converting a subsampled YCbCr image to a full-color format.
// This option is only used when the output is RGBA (either because
// ToRGBA is true or the source JPEG is in the RGB format).
UpsampleMethod UpsampleMethod
// AutoRotate enables automatic image rotation based on the EXIF orientation tag.
// If true, the decoded image will be rotated/flipped to match the intended viewing orientation.
// This process forces the output to RGBA if a transformation is applied.
AutoRotate bool
// ScaleDenom specifies the IDCT scaling denominator for efficient downscaling.
// Valid values are 1 (no scaling), 2 (1/2 size), 4 (1/4 size), or 8 (1/8 size).
// Invalid values will be clamped to the nearest valid value.
// This produces higher quality and faster decoding than decoding full size and then downsampling.
ScaleDenom int
}
Options specifies decoding parameters.
type UpsampleMethod ¶
type UpsampleMethod int
UpsampleMethod defines the algorithm used for chroma upsampling.
const ( // NearestNeighbor is a fast but low-quality upsampling method. NearestNeighbor UpsampleMethod = iota // CatmullRom is a higher-quality bicubic upsampling method. CatmullRom )