pub struct Image {
pub bytes: Arc<[u8]>,
pub format: ImageFormat,
pub width_px: u32,
pub height_px: u32,
pub components: u8,
pub common: Common,
pub alt: Option<String>,
}Expand description
A validated, embeddable JPEG or PNG. bytes are the original file
bytes, kept as-is — pixel decoding (only ever needed for PNG, to split
out the alpha channel as a SMask) happens later, in the facade.
serde (issue #17): serializes as {"bytes_base64": "...", "common": {..}} — format/width_px/height_px/components are re-derived
by re-running Image::new’s own header validation on deserialize
rather than trusting redundant JSON fields that could disagree with
the actual bytes.
Fields§
§bytes: Arc<[u8]>§format: ImageFormat§width_px: u32§height_px: u32§components: u81 = Gray, 3 = RGB, 4 = RGBA (JPEG is always 1 or 3, never 4).
common: Common§alt: Option<String>Alternate text description (issue #27) — becomes /Alt on this
image’s /Figure structure element when Document::pdf_ua() is
set. None still renders (and still gets a /Figure tag, with an
empty /Alt so the structure tree stays well-formed) but
render_with_diagnostics() reports a
LayoutWarningKind::MissingAltText for it — and, verified against
veraPDF, the resulting PDF genuinely isn’t PDF/UA-1-conformant
until real alt text is supplied (an empty /Alt doesn’t satisfy
it; this crate won’t invent placeholder text, since that would
mislead a screen reader user worse than an honest gap does).
Implementations§
Source§impl Image
impl Image
Sourcepub fn new(bytes: impl Into<Arc<[u8]>>) -> Result<Image, ImageError>
pub fn new(bytes: impl Into<Arc<[u8]>>) -> Result<Image, ImageError>
Validates bytes as a supported JPEG or PNG and extracts the
metadata layout needs (dimensions, color components). Rejects
anything outside V1’s explicit scope instead of a silent
best-effort attempt (phases/phase-5-images.md step 2-3).
Sourcepub fn alt(self, alt: impl Into<String>) -> Image
pub fn alt(self, alt: impl Into<String>) -> Image
Sets this image’s alternate text description (issue #27) — see the
alt field’s doc comment.