10个不稳定版本 (3个破坏性更改)
0.4.3 | 2024年5月22日 |
---|---|
0.4.2 | 2024年4月24日 |
0.3.0 | 2024年4月15日 |
0.2.0 | 2024年4月7日 |
0.1.2 | 2024年3月31日 |
#199 in 图形API
31KB
523 行
css-image
Rust 用于从CSS渲染图像的 crate
功能
目前仅支持 px 单位。
- 宽度/高度
- 背景颜色,颜色
- 字体大小,字体族,字体粗细,字体样式,内容,文本对齐
- 外边距
- 填充
- * 选择器
- 边框,边框半径,边框颜色,边框宽度,边框样式
- 多个选择器
依赖项
- cairo
用法
use css_image::render;
fn main() {
let css = r#"
body {
background-color: red;
width: 100px;
height: 100px;
}
"#;
let images = render(css).unwrap(); // Returns a hashmap of css selector -> Image
}
use css_image::{render, Styles};
let css = r#"
body {
background-color: red;
width: 100px;
height: 100px;
}
"#;
let mut styles = css.parse::<Styles>().unwrap(); // Parse css string to Styles for easier access
styles.get_mut("body").unwrap().content.replace("Hello world!".into()); // Set content of body to "Hello world!"
let images = render(styles).unwrap(); // Returns a hashmap of css selector -> Image
依赖项
~4–6MB
~115K SLoC