pub struct Image { /* private fields */ }Expand description
Represents an image that can be embedded in a PDF
Implementations§
Source§impl Image
impl Image
Sourcepub fn from_jpeg_file<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn from_jpeg_file<P: AsRef<Path>>(path: P) -> Result<Self>
Load a JPEG image from a file
Sourcepub fn from_jpeg_data(data: Vec<u8>) -> Result<Self>
pub fn from_jpeg_data(data: Vec<u8>) -> Result<Self>
Create an image from JPEG data
Sourcepub fn from_png_file<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn from_png_file<P: AsRef<Path>>(path: P) -> Result<Self>
Load a PNG image from a file
Sourcepub fn from_png_data(data: Vec<u8>) -> Result<Self>
pub fn from_png_data(data: Vec<u8>) -> Result<Self>
Create an image from PNG data with full transparency support
Sourcepub fn from_tiff_file<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn from_tiff_file<P: AsRef<Path>>(path: P) -> Result<Self>
Load a TIFF image from a file
Sourcepub fn from_tiff_data(data: Vec<u8>) -> Result<Self>
pub fn from_tiff_data(data: Vec<u8>) -> Result<Self>
Create an image from TIFF data
Sourcepub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self>
Load an image from a file, detecting format by extension.
Supported extensions: .jpg, .jpeg, .png, .tif, .tiff (case-insensitive).
§Example
use oxidize_pdf::Image;
let img = Image::from_file("photo.jpg").unwrap();
let img = Image::from_file("logo.png").unwrap();Sourcepub fn format(&self) -> ImageFormat
pub fn format(&self) -> ImageFormat
Get image format
Sourcepub fn bits_per_component(&self) -> u8
pub fn bits_per_component(&self) -> u8
Get bits per component
Sourcepub fn from_raw_data(
data: Vec<u8>,
width: u32,
height: u32,
color_space: ColorSpace,
bits_per_component: u8,
) -> Self
pub fn from_raw_data( data: Vec<u8>, width: u32, height: u32, color_space: ColorSpace, bits_per_component: u8, ) -> Self
Create image from raw RGB/Gray data (no encoding/compression)
Sourcepub fn from_rgba_data(
rgba_data: Vec<u8>,
width: u32,
height: u32,
) -> Result<Self>
pub fn from_rgba_data( rgba_data: Vec<u8>, width: u32, height: u32, ) -> Result<Self>
Create an image from RGBA data (with alpha channel)
Sourcepub fn from_gray_data(
gray_data: Vec<u8>,
width: u32,
height: u32,
) -> Result<Self>
pub fn from_gray_data( gray_data: Vec<u8>, width: u32, height: u32, ) -> Result<Self>
Create a grayscale image from gray data
Sourcepub fn from_file_raw<P: AsRef<Path>>(
path: P,
width: u32,
height: u32,
format: ImageFormat,
) -> Result<Self>
pub fn from_file_raw<P: AsRef<Path>>( path: P, width: u32, height: u32, format: ImageFormat, ) -> Result<Self>
Load raw image data from file (simple implementation without external image crate)
Sourcepub fn to_pdf_object(&self) -> Object
pub fn to_pdf_object(&self) -> Object
Convert to PDF XObject
Sourcepub fn to_pdf_object_with_transparency(
&self,
) -> Result<(Object, Option<Object>)>
pub fn to_pdf_object_with_transparency( &self, ) -> Result<(Object, Option<Object>)>
Convert to PDF XObject with SMask for transparency
Sourcepub fn has_transparency(&self) -> bool
pub fn has_transparency(&self) -> bool
Check if this image has transparency
Sourcepub fn create_stencil_mask(&self, threshold: u8) -> Option<Image>
pub fn create_stencil_mask(&self, threshold: u8) -> Option<Image>
Create a stencil mask from this image A stencil mask uses 1-bit per pixel for transparency
Sourcepub fn create_mask(
&self,
mask_type: MaskType,
threshold: Option<u8>,
) -> Option<Image>
pub fn create_mask( &self, mask_type: MaskType, threshold: Option<u8>, ) -> Option<Image>
Create an image mask for transparency
Sourcepub fn alpha_data(&self) -> Option<&[u8]>
pub fn alpha_data(&self) -> Option<&[u8]>
Get the alpha data if present