Crate make_quote
source ·Expand description
This library provide a single function [make_quote_image
] to turn somebody’s quote into an
image.
This is not an feature rich library. You may meet some draw issue. Feel free to open issue at GitHub to help me improve this library. Currently the best practice is to set the output size to 1920x1080.
Usage
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
.build();
// Create image configuration
let config = ImgConfig::builder()
.username("V5电竞俱乐部中单选手 Otto")
.avatar("./assets/avatar.png")
.quote("大家好,今天来点大家想看的东西。")
.build();
// 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 generate the below output: