| Crates.io | poster_generator |
| lib.rs | poster_generator |
| version | 0.1.2 |
| created_at | 2025-10-17 05:29:11.920676+00 |
| updated_at | 2025-10-21 08:45:06.192856+00 |
| description | A poster generation library based on Skia Safe with RTL text support for Arabic, Hebrew, Persian, and Uyghur |
| homepage | |
| repository | https://github.com/menzil/poster-generator |
| max_upload_size | |
| id | 1887183 |
| size | 88,280 |
一个基于 Rust 和 Skia Safe 的海报生成库,支持 RTL (从右到左) 文本渲染,适用于阿拉伯语、希伯来语、波斯语和维吾尔语等语言。
A poster generation library based on Skia Safe with RTL (Right-to-Left) text support for Arabic, Hebrew, Persian, and Uyghur languages.
将以下内容添加到你的 Cargo.toml:
[dependencies]
poster_generator = "0.1"
或使用 cargo add:
cargo add poster_generator
cargo install poster_generator
use poster_generator::{PosterGenerator, TextElement, TextAlignType, TextDirectionType};
fn main() -> anyhow::Result<()> {
// 创建生成器
let mut generator = PosterGenerator::new(800, 600, "#ffffff".to_string());
// 添加文本元素
let text = TextElement {
text: "Hello, World!".to_string(),
x: 400.0,
y: 300.0,
font_size: 48.0,
color: "#333333".to_string(),
align: TextAlignType::Center,
..Default::default()
};
generator.add_text(text);
// 生成并保存
generator.generate_file("output.png")?;
Ok(())
}
use poster_generator::{PosterGenerator, TextElement, TextAlignType, TextDirectionType};
fn main() -> anyhow::Result<()> {
let mut generator = PosterGenerator::new(800, 600, "#f8f9fa".to_string());
// 维吾尔语文本
let uyghur_text = TextElement {
text: "ئۇيغۇر تىلى".to_string(),
x: 400.0,
y: 200.0,
font_size: 48.0,
color: "#2c3e50".to_string(),
align: TextAlignType::Center,
direction: TextDirectionType::Rtl,
font_family: Some("ALKATIP Basma Tom".to_string()),
..Default::default()
};
// 阿拉伯语文本
let arabic_text = TextElement {
text: "مرحبا بالعالم".to_string(),
x: 400.0,
y: 300.0,
font_size: 36.0,
color: "#0066cc".to_string(),
align: TextAlignType::Center,
direction: TextDirectionType::Rtl,
background_color: Some("#e6f7ff".to_string()),
padding: 10.0,
..Default::default()
};
generator.add_text(uyghur_text);
generator.add_text(arabic_text);
generator.generate_file("rtl_poster.png")?;
Ok(())
}
# 从 JSON 配置文件生成海报
poster_generator -c config.json -o output.png
# 生成 base64 输出
poster_generator -c config.json -o output.png --base64
# 运行示例
poster_generator_example
{
"width": 800,
"height": 600,
"background_color": "#ffffff",
"elements": [
{
"type": "background",
"color": "#f5f5f5",
"radius": 20
},
{
"type": "image",
"src": "photo.jpg",
"x": 50,
"y": 50,
"width": 700,
"height": 400,
"radius": 10,
"object_fit": "cover",
"z_index": 1
},
{
"type": "text",
"text": "Hello, World!",
"x": 400,
"y": 500,
"font_size": 48,
"color": "#333333",
"align": "center",
"bold": true,
"z_index": 2
}
]
}
本库自动检测并支持以下语言的 RTL 文本渲染:
This library automatically detects and supports RTL text rendering for:
direction: "rtl" 手动指定 / Use direction: "rtl" to manually specifyfont_family 指定 / System auto-selects fonts, or specify via font_familyalign: "right" 或 align: "center" / RTL text usually uses right or center alignment完整 API 文档请访问 docs.rs
For complete API documentation, visit docs.rs
MIT License - 详见 LICENSE 文件
MIT License - See LICENSE file for details
欢迎贡献!请随时提交 Pull Request。
Contributions are welcome! Feel free to submit a Pull Request.