SiImage

Struct SiImage 

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

Represents an image with text rendering capabilities.

Implementations§

Source§

impl SiImage

Source

pub fn new(src: Vec<u8>) -> Self

Creates a new SiImage from a vector of image data.

§Arguments
  • src - The vector of image data.
Source

pub fn from_vec(vec: Vec<u8>) -> SiImage

Creates a new SiImage from a vector of image data.

Source

pub async fn from_network_async(image_url: &str) -> SiImage

Creates a new SiImage from image data fetched from a network URL asynchronously.

§Arguments
  • image_url - The URL from which to fetch the image data.
Source

pub fn from_network(image_url: &str) -> SiImage

Creates a new SiImage from image data fetched from a network URL synchronously.

§Arguments
  • image_url - The URL from which to fetch the image data.
Examples found in repository?
examples/image.rs (line 7)
5fn main() {
6    // Create the image
7    let mut img = SiImage::from_network("https://res.cloudinary.com/zype/image/upload/regraphic");
8    // Create the font
9    let font = SiFont::from_network(
10        "https://github.com/Zype-Z/ShareImage.js/raw/main/assets/fonts/sirin-stencil.ttf",
11    );
12    // Render some text
13    let text_options = TextOptions::default();
14    // img.render_text("Hello, World!", 64.0, 480.0, 254.0, None, &font, &text_options);
15    // Render something else
16    // img.render_text("Hello, World!", 48.0, 480.0, 320.0, None, &font, &text_options);
17    // Or do chained
18    img = img
19        .clone()
20        .render_text(
21            "Hello, World!",
22            64.0,
23            480.0,
24            254.0,
25            None,
26            &font,
27            &text_options,
28        )
29        .render_text(
30            "Hello, Another!",
31            48.0,
32            480.0,
33            320.0,
34            None,
35            &font,
36            &text_options,
37        );
38    // Write it
39    let mut file = fs::OpenOptions::new()
40        .create(true) // To create a new file
41        .write(true) // To write
42        .open("out.png")
43        .unwrap();
44    file.write_all(&img.to_bytes()).unwrap();
45}
More examples
Hide additional examples
examples/macros.rs (line 21)
7fn main() {
8    // Create it with macro
9    preset! {
10        my_preset(img, font: SiFont, title: String, tagline: String) {
11            println!("{}", title);
12            let mut new = img;
13            render!(new: title; 480.0, 254.0; "font" &font, "scale" 64.0, "opts" &TextOptions::default(), "color" None);
14            render!(new: tagline; 480.0, 320.0; "font" &font, "scale" 48.0, "opts" &TextOptions::default(), "color" Some(String::from("#FFFFFF")));
15            new
16        }
17    };
18
19    // Use it
20    // Create the image
21    let mut img = SiImage::from_network("https://res.cloudinary.com/zype/image/upload/regraphic");
22    // Create the font
23    let font = SiFont::from_network(
24        "https://github.com/Zype-Z/ShareImage.js/raw/main/assets/fonts/sirin-stencil.ttf",
25    );
26    img.load_preset(
27        my_preset,
28        anymap! {
29            font: font,
30            title: "Hello, World!".to_string(),
31            tagline: "Cool!".to_string()
32        },
33    );
34    let mut file = fs::OpenOptions::new()
35        .create(true) // To create a new file
36        .write(true)
37        // either use the ? operator or unwrap since it returns a Result
38        .open("out.png")
39        .unwrap();
40    file.write_all(&img.to_bytes()).unwrap();
41}
examples/preset.rs (line 54)
5fn main() {
6    // Create the preset
7    let preset = SiPreset::new(Box::new(|img, vals| {
8        let new_img = img.clone();
9        // img is the full image
10        println!("Dimensions: {}x{}", img.width(), img.height());
11        println!("Values: {:?}", vals);
12        // Get the font
13        let font = match vals.get("font") {
14            Some(font) => {
15                // Do type checking
16                if font.type_id() == std::any::TypeId::of::<SiFont>() {
17                    // Downcast it
18                    font.downcast_ref::<SiFont>().unwrap()
19                } else {
20                    panic!(
21                        "Expected type: {:?}\nFound type: {:?}",
22                        std::any::TypeId::of::<SiFont>(),
23                        font.type_id()
24                    );
25                }
26            }
27            None => panic!("No font provided"),
28        };
29        // Render something on the image with that font
30        // Get the title
31        let title = match vals.get("title") {
32            Some(title) => {
33                // Do type checking
34                if title.type_id() == std::any::TypeId::of::<String>() {
35                    // Downcast it
36                    title.downcast_ref::<String>().unwrap()
37                } else {
38                    panic!(
39                        "Expected type: {:?}\nFound type: {:?}",
40                        std::any::TypeId::of::<String>(),
41                        title.type_id()
42                    );
43                }
44            }
45            None => panic!("No title provided"),
46        };
47        let text_options = TextOptions::default();
48        // Render it
49        new_img.render_text(title, 64.0, 480.0, 254.0, None, font, &text_options)
50    }));
51
52    // Use it
53    // Create the image
54    let mut img = SiImage::from_network("https://res.cloudinary.com/zype/image/upload/regraphic");
55    // Create the font
56    let font = SiFont::from_network(
57        "https://github.com/Zype-Z/ShareImage.js/raw/main/assets/fonts/sirin-stencil.ttf",
58    );
59    let font_val: Box<dyn std::any::Any> = Box::new(font);
60    let title_val: Box<dyn std::any::Any> = Box::new("Hello, World!".to_string());
61    let values: HashMap<String, Box<dyn std::any::Any>> = HashMap::from([
62        ("font".to_string(), font_val),
63        ("title".to_string(), title_val),
64    ]);
65    img.load_preset(preset, values);
66    let mut file = fs::OpenOptions::new()
67        .create(true) // To create a new file
68        .write(true)
69        // either use the ? operator or unwrap since it returns a Result
70        .open("out.png")
71        .unwrap();
72    file.write_all(&img.to_bytes()).unwrap();
73}
Source

pub fn render_text( self, text: &str, text_scale: f32, pos_x: f32, pos_y: f32, color: Option<String>, using_font: &SiFont, options: &TextOptions, ) -> SiImage

Renders text onto the image.

§Arguments
  • text - The text to render on the image.
  • text_scale - The scale of the rendered text.
  • pos_x - The X-coordinate position for rendering.
  • pos_y - The Y-coordinate position for rendering.
  • color - The color of the rendered text in hexadecimal format (e.g., “#RRGGBB”).
  • using_font - The SiFont used for text rendering on the image.
§Returns

A mutable instance of the main image, with the text rendered on it.

Examples found in repository?
examples/image.rs (lines 20-28)
5fn main() {
6    // Create the image
7    let mut img = SiImage::from_network("https://res.cloudinary.com/zype/image/upload/regraphic");
8    // Create the font
9    let font = SiFont::from_network(
10        "https://github.com/Zype-Z/ShareImage.js/raw/main/assets/fonts/sirin-stencil.ttf",
11    );
12    // Render some text
13    let text_options = TextOptions::default();
14    // img.render_text("Hello, World!", 64.0, 480.0, 254.0, None, &font, &text_options);
15    // Render something else
16    // img.render_text("Hello, World!", 48.0, 480.0, 320.0, None, &font, &text_options);
17    // Or do chained
18    img = img
19        .clone()
20        .render_text(
21            "Hello, World!",
22            64.0,
23            480.0,
24            254.0,
25            None,
26            &font,
27            &text_options,
28        )
29        .render_text(
30            "Hello, Another!",
31            48.0,
32            480.0,
33            320.0,
34            None,
35            &font,
36            &text_options,
37        );
38    // Write it
39    let mut file = fs::OpenOptions::new()
40        .create(true) // To create a new file
41        .write(true) // To write
42        .open("out.png")
43        .unwrap();
44    file.write_all(&img.to_bytes()).unwrap();
45}
More examples
Hide additional examples
examples/preset.rs (line 49)
5fn main() {
6    // Create the preset
7    let preset = SiPreset::new(Box::new(|img, vals| {
8        let new_img = img.clone();
9        // img is the full image
10        println!("Dimensions: {}x{}", img.width(), img.height());
11        println!("Values: {:?}", vals);
12        // Get the font
13        let font = match vals.get("font") {
14            Some(font) => {
15                // Do type checking
16                if font.type_id() == std::any::TypeId::of::<SiFont>() {
17                    // Downcast it
18                    font.downcast_ref::<SiFont>().unwrap()
19                } else {
20                    panic!(
21                        "Expected type: {:?}\nFound type: {:?}",
22                        std::any::TypeId::of::<SiFont>(),
23                        font.type_id()
24                    );
25                }
26            }
27            None => panic!("No font provided"),
28        };
29        // Render something on the image with that font
30        // Get the title
31        let title = match vals.get("title") {
32            Some(title) => {
33                // Do type checking
34                if title.type_id() == std::any::TypeId::of::<String>() {
35                    // Downcast it
36                    title.downcast_ref::<String>().unwrap()
37                } else {
38                    panic!(
39                        "Expected type: {:?}\nFound type: {:?}",
40                        std::any::TypeId::of::<String>(),
41                        title.type_id()
42                    );
43                }
44            }
45            None => panic!("No title provided"),
46        };
47        let text_options = TextOptions::default();
48        // Render it
49        new_img.render_text(title, 64.0, 480.0, 254.0, None, font, &text_options)
50    }));
51
52    // Use it
53    // Create the image
54    let mut img = SiImage::from_network("https://res.cloudinary.com/zype/image/upload/regraphic");
55    // Create the font
56    let font = SiFont::from_network(
57        "https://github.com/Zype-Z/ShareImage.js/raw/main/assets/fonts/sirin-stencil.ttf",
58    );
59    let font_val: Box<dyn std::any::Any> = Box::new(font);
60    let title_val: Box<dyn std::any::Any> = Box::new("Hello, World!".to_string());
61    let values: HashMap<String, Box<dyn std::any::Any>> = HashMap::from([
62        ("font".to_string(), font_val),
63        ("title".to_string(), title_val),
64    ]);
65    img.load_preset(preset, values);
66    let mut file = fs::OpenOptions::new()
67        .create(true) // To create a new file
68        .write(true)
69        // either use the ? operator or unwrap since it returns a Result
70        .open("out.png")
71        .unwrap();
72    file.write_all(&img.to_bytes()).unwrap();
73}
Source

pub fn render_image(self, image: &SiImage, pos_x: i64, pos_y: i64) -> SiImage

Renders some image into the image

§Arguments
  • image - The SiImage to render.
  • pos_x - The X-coordinate position for rendering.
  • pos_y - The Y-coordinate position for rendering.
§Returns

A mutable instance of the main image, with overlay of the provided one

Source

pub fn to_bytes(&self) -> Vec<u8>

Gets the image data as bytes in PNG format.

§Returns

The image data as bytes in PNG format

Examples found in repository?
examples/image.rs (line 44)
5fn main() {
6    // Create the image
7    let mut img = SiImage::from_network("https://res.cloudinary.com/zype/image/upload/regraphic");
8    // Create the font
9    let font = SiFont::from_network(
10        "https://github.com/Zype-Z/ShareImage.js/raw/main/assets/fonts/sirin-stencil.ttf",
11    );
12    // Render some text
13    let text_options = TextOptions::default();
14    // img.render_text("Hello, World!", 64.0, 480.0, 254.0, None, &font, &text_options);
15    // Render something else
16    // img.render_text("Hello, World!", 48.0, 480.0, 320.0, None, &font, &text_options);
17    // Or do chained
18    img = img
19        .clone()
20        .render_text(
21            "Hello, World!",
22            64.0,
23            480.0,
24            254.0,
25            None,
26            &font,
27            &text_options,
28        )
29        .render_text(
30            "Hello, Another!",
31            48.0,
32            480.0,
33            320.0,
34            None,
35            &font,
36            &text_options,
37        );
38    // Write it
39    let mut file = fs::OpenOptions::new()
40        .create(true) // To create a new file
41        .write(true) // To write
42        .open("out.png")
43        .unwrap();
44    file.write_all(&img.to_bytes()).unwrap();
45}
More examples
Hide additional examples
examples/macros.rs (line 40)
7fn main() {
8    // Create it with macro
9    preset! {
10        my_preset(img, font: SiFont, title: String, tagline: String) {
11            println!("{}", title);
12            let mut new = img;
13            render!(new: title; 480.0, 254.0; "font" &font, "scale" 64.0, "opts" &TextOptions::default(), "color" None);
14            render!(new: tagline; 480.0, 320.0; "font" &font, "scale" 48.0, "opts" &TextOptions::default(), "color" Some(String::from("#FFFFFF")));
15            new
16        }
17    };
18
19    // Use it
20    // Create the image
21    let mut img = SiImage::from_network("https://res.cloudinary.com/zype/image/upload/regraphic");
22    // Create the font
23    let font = SiFont::from_network(
24        "https://github.com/Zype-Z/ShareImage.js/raw/main/assets/fonts/sirin-stencil.ttf",
25    );
26    img.load_preset(
27        my_preset,
28        anymap! {
29            font: font,
30            title: "Hello, World!".to_string(),
31            tagline: "Cool!".to_string()
32        },
33    );
34    let mut file = fs::OpenOptions::new()
35        .create(true) // To create a new file
36        .write(true)
37        // either use the ? operator or unwrap since it returns a Result
38        .open("out.png")
39        .unwrap();
40    file.write_all(&img.to_bytes()).unwrap();
41}
examples/preset.rs (line 72)
5fn main() {
6    // Create the preset
7    let preset = SiPreset::new(Box::new(|img, vals| {
8        let new_img = img.clone();
9        // img is the full image
10        println!("Dimensions: {}x{}", img.width(), img.height());
11        println!("Values: {:?}", vals);
12        // Get the font
13        let font = match vals.get("font") {
14            Some(font) => {
15                // Do type checking
16                if font.type_id() == std::any::TypeId::of::<SiFont>() {
17                    // Downcast it
18                    font.downcast_ref::<SiFont>().unwrap()
19                } else {
20                    panic!(
21                        "Expected type: {:?}\nFound type: {:?}",
22                        std::any::TypeId::of::<SiFont>(),
23                        font.type_id()
24                    );
25                }
26            }
27            None => panic!("No font provided"),
28        };
29        // Render something on the image with that font
30        // Get the title
31        let title = match vals.get("title") {
32            Some(title) => {
33                // Do type checking
34                if title.type_id() == std::any::TypeId::of::<String>() {
35                    // Downcast it
36                    title.downcast_ref::<String>().unwrap()
37                } else {
38                    panic!(
39                        "Expected type: {:?}\nFound type: {:?}",
40                        std::any::TypeId::of::<String>(),
41                        title.type_id()
42                    );
43                }
44            }
45            None => panic!("No title provided"),
46        };
47        let text_options = TextOptions::default();
48        // Render it
49        new_img.render_text(title, 64.0, 480.0, 254.0, None, font, &text_options)
50    }));
51
52    // Use it
53    // Create the image
54    let mut img = SiImage::from_network("https://res.cloudinary.com/zype/image/upload/regraphic");
55    // Create the font
56    let font = SiFont::from_network(
57        "https://github.com/Zype-Z/ShareImage.js/raw/main/assets/fonts/sirin-stencil.ttf",
58    );
59    let font_val: Box<dyn std::any::Any> = Box::new(font);
60    let title_val: Box<dyn std::any::Any> = Box::new("Hello, World!".to_string());
61    let values: HashMap<String, Box<dyn std::any::Any>> = HashMap::from([
62        ("font".to_string(), font_val),
63        ("title".to_string(), title_val),
64    ]);
65    img.load_preset(preset, values);
66    let mut file = fs::OpenOptions::new()
67        .create(true) // To create a new file
68        .write(true)
69        // either use the ? operator or unwrap since it returns a Result
70        .open("out.png")
71        .unwrap();
72    file.write_all(&img.to_bytes()).unwrap();
73}
Source

pub fn height(&self) -> u32

Gets the height of the image.

§Returns

The height of the image

Examples found in repository?
examples/preset.rs (line 10)
5fn main() {
6    // Create the preset
7    let preset = SiPreset::new(Box::new(|img, vals| {
8        let new_img = img.clone();
9        // img is the full image
10        println!("Dimensions: {}x{}", img.width(), img.height());
11        println!("Values: {:?}", vals);
12        // Get the font
13        let font = match vals.get("font") {
14            Some(font) => {
15                // Do type checking
16                if font.type_id() == std::any::TypeId::of::<SiFont>() {
17                    // Downcast it
18                    font.downcast_ref::<SiFont>().unwrap()
19                } else {
20                    panic!(
21                        "Expected type: {:?}\nFound type: {:?}",
22                        std::any::TypeId::of::<SiFont>(),
23                        font.type_id()
24                    );
25                }
26            }
27            None => panic!("No font provided"),
28        };
29        // Render something on the image with that font
30        // Get the title
31        let title = match vals.get("title") {
32            Some(title) => {
33                // Do type checking
34                if title.type_id() == std::any::TypeId::of::<String>() {
35                    // Downcast it
36                    title.downcast_ref::<String>().unwrap()
37                } else {
38                    panic!(
39                        "Expected type: {:?}\nFound type: {:?}",
40                        std::any::TypeId::of::<String>(),
41                        title.type_id()
42                    );
43                }
44            }
45            None => panic!("No title provided"),
46        };
47        let text_options = TextOptions::default();
48        // Render it
49        new_img.render_text(title, 64.0, 480.0, 254.0, None, font, &text_options)
50    }));
51
52    // Use it
53    // Create the image
54    let mut img = SiImage::from_network("https://res.cloudinary.com/zype/image/upload/regraphic");
55    // Create the font
56    let font = SiFont::from_network(
57        "https://github.com/Zype-Z/ShareImage.js/raw/main/assets/fonts/sirin-stencil.ttf",
58    );
59    let font_val: Box<dyn std::any::Any> = Box::new(font);
60    let title_val: Box<dyn std::any::Any> = Box::new("Hello, World!".to_string());
61    let values: HashMap<String, Box<dyn std::any::Any>> = HashMap::from([
62        ("font".to_string(), font_val),
63        ("title".to_string(), title_val),
64    ]);
65    img.load_preset(preset, values);
66    let mut file = fs::OpenOptions::new()
67        .create(true) // To create a new file
68        .write(true)
69        // either use the ? operator or unwrap since it returns a Result
70        .open("out.png")
71        .unwrap();
72    file.write_all(&img.to_bytes()).unwrap();
73}
Source

pub fn width(&self) -> u32

Gets the width of the image.

§Returns

The width of the image

Examples found in repository?
examples/preset.rs (line 10)
5fn main() {
6    // Create the preset
7    let preset = SiPreset::new(Box::new(|img, vals| {
8        let new_img = img.clone();
9        // img is the full image
10        println!("Dimensions: {}x{}", img.width(), img.height());
11        println!("Values: {:?}", vals);
12        // Get the font
13        let font = match vals.get("font") {
14            Some(font) => {
15                // Do type checking
16                if font.type_id() == std::any::TypeId::of::<SiFont>() {
17                    // Downcast it
18                    font.downcast_ref::<SiFont>().unwrap()
19                } else {
20                    panic!(
21                        "Expected type: {:?}\nFound type: {:?}",
22                        std::any::TypeId::of::<SiFont>(),
23                        font.type_id()
24                    );
25                }
26            }
27            None => panic!("No font provided"),
28        };
29        // Render something on the image with that font
30        // Get the title
31        let title = match vals.get("title") {
32            Some(title) => {
33                // Do type checking
34                if title.type_id() == std::any::TypeId::of::<String>() {
35                    // Downcast it
36                    title.downcast_ref::<String>().unwrap()
37                } else {
38                    panic!(
39                        "Expected type: {:?}\nFound type: {:?}",
40                        std::any::TypeId::of::<String>(),
41                        title.type_id()
42                    );
43                }
44            }
45            None => panic!("No title provided"),
46        };
47        let text_options = TextOptions::default();
48        // Render it
49        new_img.render_text(title, 64.0, 480.0, 254.0, None, font, &text_options)
50    }));
51
52    // Use it
53    // Create the image
54    let mut img = SiImage::from_network("https://res.cloudinary.com/zype/image/upload/regraphic");
55    // Create the font
56    let font = SiFont::from_network(
57        "https://github.com/Zype-Z/ShareImage.js/raw/main/assets/fonts/sirin-stencil.ttf",
58    );
59    let font_val: Box<dyn std::any::Any> = Box::new(font);
60    let title_val: Box<dyn std::any::Any> = Box::new("Hello, World!".to_string());
61    let values: HashMap<String, Box<dyn std::any::Any>> = HashMap::from([
62        ("font".to_string(), font_val),
63        ("title".to_string(), title_val),
64    ]);
65    img.load_preset(preset, values);
66    let mut file = fs::OpenOptions::new()
67        .create(true) // To create a new file
68        .write(true)
69        // either use the ? operator or unwrap since it returns a Result
70        .open("out.png")
71        .unwrap();
72    file.write_all(&img.to_bytes()).unwrap();
73}
Source

pub fn resize(self, width: u32, height: u32) -> SiImage

Resizes the image

§Arguments
  • width - The new width of the image
  • height - The new height of the image
§Returns

A mutable instance of the main image, with the resized image

Source§

impl SiImage

Source

pub fn load_preset( &mut self, preset: Box<SiPreset>, values: HashMap<String, Box<dyn Any>>, ) -> &mut SiImage

Load a preset. NOTE: It doesn’t work in WASM. Only for direct usage.

Examples found in repository?
examples/macros.rs (lines 26-33)
7fn main() {
8    // Create it with macro
9    preset! {
10        my_preset(img, font: SiFont, title: String, tagline: String) {
11            println!("{}", title);
12            let mut new = img;
13            render!(new: title; 480.0, 254.0; "font" &font, "scale" 64.0, "opts" &TextOptions::default(), "color" None);
14            render!(new: tagline; 480.0, 320.0; "font" &font, "scale" 48.0, "opts" &TextOptions::default(), "color" Some(String::from("#FFFFFF")));
15            new
16        }
17    };
18
19    // Use it
20    // Create the image
21    let mut img = SiImage::from_network("https://res.cloudinary.com/zype/image/upload/regraphic");
22    // Create the font
23    let font = SiFont::from_network(
24        "https://github.com/Zype-Z/ShareImage.js/raw/main/assets/fonts/sirin-stencil.ttf",
25    );
26    img.load_preset(
27        my_preset,
28        anymap! {
29            font: font,
30            title: "Hello, World!".to_string(),
31            tagline: "Cool!".to_string()
32        },
33    );
34    let mut file = fs::OpenOptions::new()
35        .create(true) // To create a new file
36        .write(true)
37        // either use the ? operator or unwrap since it returns a Result
38        .open("out.png")
39        .unwrap();
40    file.write_all(&img.to_bytes()).unwrap();
41}
More examples
Hide additional examples
examples/preset.rs (line 65)
5fn main() {
6    // Create the preset
7    let preset = SiPreset::new(Box::new(|img, vals| {
8        let new_img = img.clone();
9        // img is the full image
10        println!("Dimensions: {}x{}", img.width(), img.height());
11        println!("Values: {:?}", vals);
12        // Get the font
13        let font = match vals.get("font") {
14            Some(font) => {
15                // Do type checking
16                if font.type_id() == std::any::TypeId::of::<SiFont>() {
17                    // Downcast it
18                    font.downcast_ref::<SiFont>().unwrap()
19                } else {
20                    panic!(
21                        "Expected type: {:?}\nFound type: {:?}",
22                        std::any::TypeId::of::<SiFont>(),
23                        font.type_id()
24                    );
25                }
26            }
27            None => panic!("No font provided"),
28        };
29        // Render something on the image with that font
30        // Get the title
31        let title = match vals.get("title") {
32            Some(title) => {
33                // Do type checking
34                if title.type_id() == std::any::TypeId::of::<String>() {
35                    // Downcast it
36                    title.downcast_ref::<String>().unwrap()
37                } else {
38                    panic!(
39                        "Expected type: {:?}\nFound type: {:?}",
40                        std::any::TypeId::of::<String>(),
41                        title.type_id()
42                    );
43                }
44            }
45            None => panic!("No title provided"),
46        };
47        let text_options = TextOptions::default();
48        // Render it
49        new_img.render_text(title, 64.0, 480.0, 254.0, None, font, &text_options)
50    }));
51
52    // Use it
53    // Create the image
54    let mut img = SiImage::from_network("https://res.cloudinary.com/zype/image/upload/regraphic");
55    // Create the font
56    let font = SiFont::from_network(
57        "https://github.com/Zype-Z/ShareImage.js/raw/main/assets/fonts/sirin-stencil.ttf",
58    );
59    let font_val: Box<dyn std::any::Any> = Box::new(font);
60    let title_val: Box<dyn std::any::Any> = Box::new("Hello, World!".to_string());
61    let values: HashMap<String, Box<dyn std::any::Any>> = HashMap::from([
62        ("font".to_string(), font_val),
63        ("title".to_string(), title_val),
64    ]);
65    img.load_preset(preset, values);
66    let mut file = fs::OpenOptions::new()
67        .create(true) // To create a new file
68        .write(true)
69        // either use the ? operator or unwrap since it returns a Result
70        .open("out.png")
71        .unwrap();
72    file.write_all(&img.to_bytes()).unwrap();
73}

Trait Implementations§

Source§

impl Clone for SiImage

Source§

fn clone(&self) -> SiImage

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl From<SiImage> for JsValue

Source§

fn from(value: SiImage) -> Self

Converts to this type from the input type.
Source§

impl FromWasmAbi for SiImage

Source§

type Abi = u32

The Wasm ABI type that this converts from when coming back out from the ABI boundary.
Source§

unsafe fn from_abi(js: u32) -> Self

Recover a Self from Self::Abi. Read more
Source§

impl IntoWasmAbi for SiImage

Source§

type Abi = u32

The Wasm ABI type that this converts into when crossing the ABI boundary.
Source§

fn into_abi(self) -> u32

Convert self into Self::Abi so that it can be sent across the wasm ABI boundary.
Source§

impl LongRefFromWasmAbi for SiImage

Source§

type Abi = u32

Same as RefFromWasmAbi::Abi
Source§

type Anchor = RcRef<SiImage>

Same as RefFromWasmAbi::Anchor
Source§

unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor

Same as RefFromWasmAbi::ref_from_abi
Source§

impl OptionFromWasmAbi for SiImage

Source§

fn is_none(abi: &Self::Abi) -> bool

Tests whether the argument is a “none” instance. If so it will be deserialized as None, and otherwise it will be passed to FromWasmAbi.
Source§

impl OptionIntoWasmAbi for SiImage

Source§

fn none() -> Self::Abi

Returns an ABI instance indicating “none”, which JS will interpret as the None branch of this option. Read more
Source§

impl RefFromWasmAbi for SiImage

Source§

type Abi = u32

The Wasm ABI type references to Self are recovered from.
Source§

type Anchor = RcRef<SiImage>

The type that holds the reference to Self for the duration of the invocation of the function that has an &Self parameter. This is required to ensure that the lifetimes don’t persist beyond one function call, and so that they remain anonymous.
Source§

unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor

Recover a Self::Anchor from Self::Abi. Read more
Source§

impl RefMutFromWasmAbi for SiImage

Source§

type Abi = u32

Same as RefFromWasmAbi::Abi
Source§

type Anchor = RcRefMut<SiImage>

Same as RefFromWasmAbi::Anchor
Source§

unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor

Same as RefFromWasmAbi::ref_from_abi
Source§

impl TryFromJsValue for SiImage

Source§

type Error = JsValue

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

fn try_from_js_value(value: JsValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl VectorFromWasmAbi for SiImage

Source§

type Abi = <Box<[JsValue]> as FromWasmAbi>::Abi

Source§

unsafe fn vector_from_abi(js: Self::Abi) -> Box<[SiImage]>

Source§

impl VectorIntoWasmAbi for SiImage

Source§

impl WasmDescribe for SiImage

Source§

impl WasmDescribeVector for SiImage

Source§

impl SupportsConstructor for SiImage

Source§

impl SupportsInstanceProperty for SiImage

Source§

impl SupportsStaticProperty for SiImage

Auto Trait Implementations§

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> 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
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ReturnWasmAbi for T
where T: IntoWasmAbi,

Source§

type Abi = <T as IntoWasmAbi>::Abi

Same as IntoWasmAbi::Abi
Source§

fn return_abi(self) -> <T as ReturnWasmAbi>::Abi

Same as IntoWasmAbi::into_abi, except that it may throw and never return in the case of Err.
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.
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
Source§

impl<T> ErasedDestructor for T
where T: 'static,