pub struct Image { /* private fields */ }Expand description
Represents a loaded image.
Implementations§
Source§impl Image
impl Image
Sourcepub async fn new(mime: Mime, data: Vec<u8>) -> Image
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.
Sourcepub async fn process<F>(&mut self, func: F)
pub async fn process<F>(&mut self, func: F)
Process the image with a closure on a background thread
Sourcepub async fn encode(&self, mime: Mime) -> Vec<u8> ⓘ
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.
Sourcepub async fn encode_png(&self) -> Vec<u8> ⓘ
pub async fn encode_png(&self) -> Vec<u8> ⓘ
Encodes the image as PNG.
Sourcepub async fn encode_jpeg(&self, _quality: u8) -> Vec<u8> ⓘ
pub async fn encode_jpeg(&self, _quality: u8) -> Vec<u8> ⓘ
Encodes the image as JPEG with the specified quality (currently unused).
Sourcepub async fn rotate(&mut self, angle: u32)
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.
Sourcepub fn dimensions(&self) -> (u32, u32)
pub fn dimensions(&self) -> (u32, u32)
Get the dimensions (width, height) of the image
Sourcepub async fn resize(&mut self, width: u32, height: u32)
pub async fn resize(&mut self, width: u32, height: u32)
Resize the image to the specified dimensions Uses Lanczos3 filter for high quality
Sourcepub async fn resize_to_fit(&mut self, max_width: u32, max_height: u32)
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
Sourcepub async fn resize_to_fill(&mut self, width: u32, height: u32)
pub async fn resize_to_fill(&mut self, width: u32, height: u32)
Resize the image to fill the specified dimensions while maintaining aspect ratio
Sourcepub async fn resize_exact(&mut self, width: u32, height: u32)
pub async fn resize_exact(&mut self, width: u32, height: u32)
Resize the image exactly to the specified dimensions (may distort aspect ratio)
Sourcepub async fn flip_horizontal(&mut self)
pub async fn flip_horizontal(&mut self)
Flip the image horizontally
Sourcepub async fn flip_vertical(&mut self)
pub async fn flip_vertical(&mut self)
Flip the image vertically
Sourcepub async fn crop(&mut self, x: u32, y: u32, width: u32, height: u32) -> bool
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
Sourcepub async fn brighten(&mut self, value: i32)
pub async fn brighten(&mut self, value: i32)
Adjust the brightness of the image value: -100 to 100 (negative for darker, positive for brighter)
Sourcepub async fn adjust_contrast(&mut self, contrast: f32)
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)
Sourcepub async fn unsharpen(&mut self, sigma: f32, threshold: i32)
pub async fn unsharpen(&mut self, sigma: f32, threshold: i32)
Apply an unsharpen mask to the image
Sourcepub fn get_pixel(&self, x: u32, y: u32) -> Option<WithOpacity<Srgb>>
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
Sourcepub async fn thumbnail(&mut self, max_size: u32)
pub async fn thumbnail(&mut self, max_size: u32)
Create a thumbnail of the image with the specified maximum dimension
Sourcepub async fn rotate_180(&mut self)
pub async fn rotate_180(&mut self)
Rotate the image 180 degrees
Sourcepub async fn rotate_270(&mut self)
pub async fn rotate_270(&mut self)
Rotate the image 270 degrees clockwise (90 degrees counter-clockwise)
Sourcepub async fn gaussian_blur(&mut self, sigma: f32)
pub async fn gaussian_blur(&mut self, sigma: f32)
Apply a Gaussian blur with the specified sigma
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)