Skip to navigation
Use a mask with a rust image library
15.05.24
# get the lib via Cargo.toml ```toml ril = { version = "*", features = ["all"] } ``` # import the lib ```rust use std::path::{Path, PathBuf}; ``` # sample code ```rust let mut image = Image::
::open(source_path).unwrap(); let (width, height) = image.dimensions(); let e = Ellipse::from_bounding_box(0, 0, width, height).with_fill(L(255)); let mut mask = Image::new(width, height, L(0)); mask.draw(&e); image.mask_alpha(&mask); image.save_inferred("sample_circle.png"); ```
https://docs.rs/ril/latest/ril/
Reply
Anonymous
```rust let mut image = Image::
::open(source_path).unwrap(); let pb = reqwest::get(&pic).await.unwrap().bytes().await.unwrap(); let mb = reqwest::get(&mask).await.unwrap().bytes().await.unwrap(); let mut pic = Image::
::from_bytes(ImageFormat2::Jpeg, pb).unwrap(); let mut _mask = Image::
::from_bytes_inferred(mb).unwrap(); //create the picture let (rgb, alpha) = _mask.split_rgb_and_alpha(); //get the alpha let mut mask: Image
= alpha.convert(); //convert the alpha into bitpixel let (width, height) = pic.dimensions(); image.resize(width, height, ResizeAlgorithm::Nearest); let mut imagex = Image::new(100, 100, Rgba::new(255, 0, 0, 255)); let mut imageb = Image::new(100, 100, Rgba::black()); pic.paste_with_mask(0, 0, &image, &mask); pic.save_inferred("sample_circle.png"); ```
15.05.24
Reply
Anonymous
Information Epoch 1725763101
When in doubt, use brute force.
Home
Notebook
Contact us