pub struct ImageContent {Show 14 fields
pub bbox: Rect,
pub format: ImageFormat,
pub data: Vec<u8>,
pub width: u32,
pub height: u32,
pub bits_per_component: u8,
pub color_space: ColorSpace,
pub reading_order: Option<usize>,
pub alt_text: Option<String>,
pub horizontal_dpi: Option<f32>,
pub vertical_dpi: Option<f32>,
pub soft_mask: Option<Vec<u8>>,
pub matrix: Option<[f32; 6]>,
pub is_artifact: bool,
}Expand description
Image content that can be extracted from or written to a PDF.
This represents an embedded image with its positioning information.
Fields§
§bbox: RectBounding box where the image is placed
format: ImageFormatImage format
data: Vec<u8>Image bytes. When constructed via from_bytes() or new() this holds the
encoded file bytes (PNG/JPEG). When extracted from an existing PDF the bytes
are the raw decoded pixel data as stored in the XObject stream.
width: u32Image width in pixels
height: u32Image height in pixels
bits_per_component: u8Bits per component (typically 8)
color_space: ColorSpaceColor space
reading_order: Option<usize>Reading order index
alt_text: Option<String>Alternative text for accessibility
horizontal_dpi: Option<f32>Horizontal DPI (dots per inch) calculated from pixel width and bbox
vertical_dpi: Option<f32>Vertical DPI (dots per inch) calculated from pixel height and bbox
soft_mask: Option<Vec<u8>>Optional alpha / transparency channel for PNG-style soft masks.
Already compressed (FlateDecode) by the image decoder. Carried
through to the PDF as an /SMask XObject so transparent PNGs
render with their alpha preserved. None for opaque images
and for formats that don’t carry transparency (JPEG, CMYK).
matrix: Option<[f32; 6]>Optional 2D affine transform in PDF row order [a b c d e f].
When set, the image is wrapped in q ... cm ... Q on emission
so graphics-state stays scoped. Populated by
FluentPageBuilder::{rotated, scaled, translated, with_transform}
closures. #393 Bundle A-2 follow-up.
is_artifact: boolWhen true the image is purely decorative and must be marked as an
/Artifact in the content stream so assistive technology ignores it.
PDF/UA-1 §7.1 (F-3). Mutually exclusive with alt_text.
Implementations§
Source§impl ImageContent
impl ImageContent
Sourcepub fn new(
bbox: Rect,
format: ImageFormat,
data: Vec<u8>,
width: u32,
height: u32,
) -> Self
pub fn new( bbox: Rect, format: ImageFormat, data: Vec<u8>, width: u32, height: u32, ) -> Self
Create a new image content element.
Sourcepub fn as_artifact(self) -> Self
pub fn as_artifact(self) -> Self
Mark this image as a decorative artifact (PDF/UA-1 §7.1). The image
will be wrapped in /Artifact BDC/EMC so assistive technology
skips it. Clears any alt_text that was previously set.
Sourcepub fn with_soft_mask(self, mask: Vec<u8>) -> Self
pub fn with_soft_mask(self, mask: Vec<u8>) -> Self
Attach a pre-compressed soft-mask (alpha) channel. The bytes are
emitted verbatim as a separate XObject stream linked via
/SMask so PDF viewers composite the alpha at paint time.
Sourcepub fn with_reading_order(self, order: usize) -> Self
pub fn with_reading_order(self, order: usize) -> Self
Set the reading order.
Sourcepub fn with_alt_text(self, text: impl Into<String>) -> Self
pub fn with_alt_text(self, text: impl Into<String>) -> Self
Set alternative text for accessibility.
Sourcepub fn aspect_ratio(&self) -> f32
pub fn aspect_ratio(&self) -> f32
Get the aspect ratio (width / height).
Sourcepub fn is_grayscale(&self) -> bool
pub fn is_grayscale(&self) -> bool
Check if this is a grayscale image.
Sourcepub fn calculate_dpi(&mut self)
pub fn calculate_dpi(&mut self)
Calculate and set the DPI values based on pixel dimensions and bounding box.
DPI = pixels / inches, where inches = points / 72 (1 inch = 72 points)
Sourcepub fn resolution(&self) -> Option<(f32, f32)>
pub fn resolution(&self) -> Option<(f32, f32)>
Get the resolution as (horizontal_dpi, vertical_dpi).
Returns None if DPI hasn’t been calculated or bbox is invalid.
Sourcepub fn get_horizontal_dpi(&self) -> Option<f32>
pub fn get_horizontal_dpi(&self) -> Option<f32>
Get the horizontal DPI.
Sourcepub fn get_vertical_dpi(&self) -> Option<f32>
pub fn get_vertical_dpi(&self) -> Option<f32>
Get the vertical DPI.
Sourcepub fn is_high_resolution(&self) -> bool
pub fn is_high_resolution(&self) -> bool
Check if this image is high resolution (>= 300 DPI in both dimensions).
300 DPI is considered the standard for print-quality images.
Sourcepub fn is_low_resolution(&self) -> bool
pub fn is_low_resolution(&self) -> bool
Check if this image is low resolution (< 150 DPI in either dimension).
150 DPI is often considered the minimum for reasonable quality.
Sourcepub fn is_medium_resolution(&self) -> bool
pub fn is_medium_resolution(&self) -> bool
Check if this image is medium resolution (>= 150 DPI but < 300 DPI).
Sourcepub fn from_bytes(bbox: Rect, data: Vec<u8>) -> Result<Self, Error>
pub fn from_bytes(bbox: Rect, data: Vec<u8>) -> Result<Self, Error>
Create an ImageContent from raw image bytes, auto-detecting JPEG/PNG by magic number.
Pixel dimensions, color space, and soft mask are parsed from the image header
automatically — no need to supply width or height. bbox controls the
on-page display rectangle in PDF points (72 pt = 1 inch).
Returns an error if the bytes do not start with a recognised image magic number.