Skip to main content

Image

Struct Image 

Source
pub struct Image {
    pub filename: String,
    pub width: u32,
    pub height: u32,
    pub x: u32,
    pub y: u32,
    pub format: String,
    pub source: Option<ImageSource>,
    pub crop: Option<Crop>,
    pub effects: Vec<ImageEffect>,
    pub alt_text: Option<String>,
}
Expand description

Image metadata and properties

Fields§

§filename: String§width: u32§height: u32§x: u32§y: u32§format: String§source: Option<ImageSource>

Image data source (file path, base64, or bytes)

§crop: Option<Crop>

Image cropping

§effects: Vec<ImageEffect>

Image effects

§alt_text: Option<String>

Accessibility alt text (description)

Implementations§

Source§

impl Image

Source

pub fn new(filename: &str, width: u32, height: u32, format: &str) -> Self

Create a new image

Source

pub fn from_path<P: AsRef<Path>>(path: P) -> Result<Self, String>

Create an image from a file path, automatically detecting dimensions

Source

pub fn from_base64(data: &str, width: u32, height: u32, format: &str) -> Self

Create an image from base64 encoded data

§Example
use ppt_rs::generator::Image;

let base64_data = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==";
let img = Image::from_base64(base64_data, 100, 100, "PNG")
    .position(1000000, 1000000);

assert_eq!(img.width, 100);
assert_eq!(img.height, 100);
assert_eq!(img.format, "PNG");
Source

pub fn from_bytes(data: Vec<u8>, width: u32, height: u32, format: &str) -> Self

Create an image from raw bytes

Source

pub fn with_alt_text(self, alt: &str) -> Self

Set accessibility alt text for the image.

Source

pub fn get_bytes(&self) -> Option<Vec<u8>>

Get the image data as bytes (decodes base64 if needed)

Source

pub fn position(self, x: u32, y: u32) -> Self

Set image position

Source

pub fn with_crop(self, left: f64, top: f64, right: f64, bottom: f64) -> Self

Set image cropping

Source

pub fn with_effect(self, effect: ImageEffect) -> Self

Add an image effect

Source

pub fn aspect_ratio(&self) -> f64

Get aspect ratio

Source

pub fn scale_to_width(self, width: u32) -> Self

Scale image to width while maintaining aspect ratio

Source

pub fn scale_to_height(self, height: u32) -> Self

Scale image to height while maintaining aspect ratio

Source

pub fn extension(&self) -> String

Get file extension from filename

Source

pub fn mime_type(&self) -> String

Get MIME type for the image format

Source

pub fn at(self, x: Dimension, y: Dimension) -> Self

Set position using flexible Dimension units (fluent).

Source

pub fn with_dimensions(self, width: Dimension, height: Dimension) -> Self

Set size using flexible Dimension units (fluent).

Trait Implementations§

Source§

impl Clone for Image

Source§

fn clone(&self) -> Image

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Image

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Positioned for Image

Source§

fn x(&self) -> u32

Get X position in EMU
Source§

fn y(&self) -> u32

Get Y position in EMU
Source§

fn set_position(&mut self, x: u32, y: u32)

Set position
Source§

impl Sized for Image

Source§

fn width(&self) -> u32

Get width in EMU
Source§

fn height(&self) -> u32

Get height in EMU
Source§

fn set_size(&mut self, width: u32, height: u32)

Set size

Auto Trait Implementations§

§

impl Freeze for Image

§

impl RefUnwindSafe for Image

§

impl Send for Image

§

impl Sync for Image

§

impl Unpin for Image

§

impl UnsafeUnpin for Image

§

impl UnwindSafe for Image

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.