module

PDF::Images::Image

Unified image loader that auto-detects format.

This module provides convenience methods to load images from various sources and automatically detect whether they are JPEG or PNG format.

Usage

# Auto-detect format from file extension
image = PDF::Images::Image.load("photo.jpg")
image = PDF::Images::Image.load("logo.png")

# Load from bytes (auto-detects by magic bytes)
image = PDF::Images::Image.load(bytes)

# Load from IO (must specify format or use magic bytes)
image = PDF::Images::Image.load(io)

Constants

JPEG_MAGIC = Bytes[255, 216]

JPEG magic bytes: FF D8

PNG_MAGIC = Bytes[137, 80, 78, 71, 13, 10, 26, 10]

PNG magic bytes: 89 50 4E 47 0D 0A 1A 0A

Class methods

jpeg?(data : Bytes) : Bool

Check if data starts with JPEG magic bytes

Source
load(path : String) : Base

Load image from file path (auto-detects format)

Source
load(data : Bytes) : Base

Load image from bytes (auto-detects format by magic bytes)

Source
load(io : IO) : Base

Load image from IO (reads all bytes and auto-detects)

Source
png?(data : Bytes) : Bool

Check if data starts with PNG magic bytes

Source