module

Vug::ImageValidator

Validates image format detection and checks if data is a valid image. Dimension extraction is in ImageDimensions (separation of concerns).

Constants

JPEG_SIGNATURE = Bytes[255, 216, 255]
PNG_SIGNATURE = Bytes[137, 80, 78, 71, 13, 10, 26, 10]
SVG_DECLARATION = Bytes[60, 63, 120, 109, 108]
SVG_SCAN_WINDOW = 1024

Window size (in bytes) to scan for tag after <?xml declaration. 1024 bytes is sufficient to handle typical XML declarations with namespaces and processing instructions before the root element.

SVG_TAG_BYTES = Bytes[60, 115, 118, 103, 32, 62, 9, 10, 13]
SVG_TAG_START = Bytes[60, 115, 118, 103]
WEBP_RIFF = Bytes[82, 73, 70, 70]
WEBP_WEBP = Bytes[87, 69, 66, 80]

Class methods

gif?(data : Bytes) : Bool

Detects GIF87a and GIF89a formats by checking magic bytes. Bytes 0-2: "GIF", byte 3: "8", byte 4: "7" or "9", byte 5: "a"

Source
ico?(data : Bytes) : Bool
Source
jpeg?(data : Bytes) : Bool
Source
png?(data : Bytes) : Bool
Source
svg?(data : Bytes) : Bool
Source
valid?(data : Bytes, hard_validation : Bool = false) : Bool
Source
webp?(data : Bytes) : Bool
Source
webp_lossy?(data : Bytes) : Bool

Returns true if the WEBP data appears to be the lossy VP8 variant.

Source