Image

Struct Image 

Source
pub struct Image { /* private fields */ }
Expand description

Represents a loaded image.

Implementations§

Source§

impl Image

Source

pub async fn new(mime: Mime, data: Vec<u8>) -> Image

Creates a new Image from raw image data.

It will decode the image on a background thread, preventing UI blocking.

§Panics

Panics if the MIME type is not supported or if the image data cannot be decoded.

Source

pub async fn process<F>(&mut self, func: F)
where F: FnOnce(Arc<DynamicImage>) -> DynamicImage + Send + 'static,

Process the image with a closure on a background thread

Source

pub async fn encode(&self, mime: Mime) -> Vec<u8>

Encodes the image to the specified MIME type.

§Panics

Panics if the MIME type is not supported or if encoding fails.

Source

pub async fn encode_png(&self) -> Vec<u8>

Encodes the image as PNG.

Source

pub async fn encode_jpeg(&self, _quality: u8) -> Vec<u8>

Encodes the image as JPEG with the specified quality (currently unused).

Source

pub async fn rotate(&mut self, angle: u32)

Rotates the image by the specified angle in degrees (0, 90, 180, or 270).

§Panics

Panics if the angle is not a multiple of 90 degrees or is outside the range 0-359.

Source

pub fn width(&self) -> u32

Get the width of the image in pixels

Source

pub fn height(&self) -> u32

Get the height of the image in pixels

Source

pub fn dimensions(&self) -> (u32, u32)

Get the dimensions (width, height) of the image

Source

pub async fn resize(&mut self, width: u32, height: u32)

Resize the image to the specified dimensions Uses Lanczos3 filter for high quality

Source

pub async fn resize_to_fit(&mut self, max_width: u32, max_height: u32)

Resize the image to fit within the specified dimensions while maintaining aspect ratio

Source

pub async fn resize_to_fill(&mut self, width: u32, height: u32)

Resize the image to fill the specified dimensions while maintaining aspect ratio

Source

pub async fn resize_exact(&mut self, width: u32, height: u32)

Resize the image exactly to the specified dimensions (may distort aspect ratio)

Source

pub async fn flip_horizontal(&mut self)

Flip the image horizontally

Source

pub async fn flip_vertical(&mut self)

Flip the image vertically

Source

pub async fn crop(&mut self, x: u32, y: u32, width: u32, height: u32) -> bool

Crop the image to the specified rectangle Returns true if successful, false if the rectangle is out of bounds

Source

pub async fn blur(&mut self, sigma: f32)

Blur the image with the specified sigma value

Source

pub async fn brighten(&mut self, value: i32)

Adjust the brightness of the image value: -100 to 100 (negative for darker, positive for brighter)

Source

pub async fn adjust_contrast(&mut self, contrast: f32)

Adjust the contrast of the image contrast: floating point value (1.0 = no change, < 1.0 = less contrast, > 1.0 = more contrast)

Source

pub async fn grayscale(&mut self)

Convert the image to grayscale

Source

pub async fn invert(&mut self)

Invert the colors of the image

Source

pub async fn unsharpen(&mut self, sigma: f32, threshold: i32)

Apply an unsharpen mask to the image

Source

pub fn get_pixel(&self, x: u32, y: u32) -> Option<WithOpacity<Srgb>>

Get the color of a specific pixel Returns None if the coordinates are out of bounds

Source

pub async fn thumbnail(&mut self, max_size: u32)

Create a thumbnail of the image with the specified maximum dimension

Source

pub async fn rotate_90(&mut self)

Rotate the image 90 degrees clockwise

Source

pub async fn rotate_180(&mut self)

Rotate the image 180 degrees

Source

pub async fn rotate_270(&mut self)

Rotate the image 270 degrees clockwise (90 degrees counter-clockwise)

Source

pub async fn gaussian_blur(&mut self, sigma: f32)

Apply a Gaussian blur with the specified sigma

Source

pub async fn huerotate(&mut self, degrees: i32)

Hue rotate the image by the specified degrees

Source

pub const fn mime(&self) -> &Mime

Get the MIME type of the image

Source

pub async fn write( &self, format: Mime, path: impl AsRef<Path>, ) -> Result<(), Error>

Write the image to a file with the specified format

§Errors

Returns an error if the file cannot be written.

Source

pub async fn url(&self) -> String

Generate a base64-encoded data URL for the image encoded as PNG

For large images (>10KB), encoding is done on a background thread to prevent UI blocking.

Trait Implementations§

Source§

impl Clone for Image

Source§

fn clone(&self) -> Image

Returns a duplicate of the value. Read more
1.0.0§

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<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Image

§

impl RefUnwindSafe for Image

§

impl Send for Image

§

impl Sync for Image

§

impl Unpin for Image

§

impl UnwindSafe for Image

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

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

§

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
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> IdentifiableExt for T

Source§

fn use_id<F, Id>(self, f: F) -> UseId<Self, F>
where F: Fn(&Self) -> Id, Id: Ord + Hash,

Wraps the value in a UseId with the provided identification function.
Source§

fn self_id(self) -> SelfId<Self>

Wraps the value in a SelfId, making the value serve as its own identifier.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
§

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

§

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
§

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

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

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

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more