#image #generate


A funny toy project that can help you generate a image from someone's quote

6 releases

0.2.4 Apr 12, 2023
0.2.3 Apr 4, 2023
0.1.0 Mar 11, 2023

#22 in #generate

40 downloads per month

MIT license

181 lines

Make quote

crates.io docs.rs

This library provides a single function that can generate a quote image from user input. It is still under development, further document and crates.io dependencies will be released someday.


use make_quote::{QuoteProducer, ImgConfig};

// First of all, load an font into memory
let font = std::fs::read("/usr/share/fonts/noto-cjk/NotoSansCJK-Regular.ttc").unwrap();

// Create a image producer
let bold_font = std::fs::read("/usr/share/fonts/noto-cjk/NotoSansCJK-Bold.ttc").unwrap();
let light_font = include_bytes!("/usr/share/fonts/noto-cjk/NotoSansCJK-Light.ttc");
let producer = QuoteProducer::builder()
    .font(&bold_font, light_font)
    .output_size(1920, 1080) // optional
    .font_scale(120.0)       // optional

// Create image configuration
let config = ImgConfig::builder()
    .username("V5电竞俱乐部中单选手 Otto")

// Then generate the image and get the image buffer
let buffer = producer.make_image(&config).unwrap();

// You can do anything you like to the buffer, save it or just send it through the net.
std::fs::write("./assets/test.jpg", buffer).unwrap();

This will provide the below example output:



~317K SLoC