image/
image.rs

1use si_img::{SiFont, SiImage, TextOptions};
2
3use std::{fs, io::Write};
4
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}