#css #image #rendering #graphics #dimension

css-image

Library for rendering images from css

9 unstable releases (3 breaking)

0.4.2 Apr 24, 2024
0.4.1 Apr 21, 2024
0.3.0 Apr 15, 2024
0.2.0 Apr 7, 2024
0.1.2 Mar 31, 2024

#129 in Graphics APIs

Download history 95/week @ 2024-03-24 400/week @ 2024-03-31 98/week @ 2024-04-07 302/week @ 2024-04-14 315/week @ 2024-04-21 15/week @ 2024-04-28

742 downloads per month

MIT license

32KB
789 lines

css-image

Rust crate for rendering images from css

Build Status codecov

Features

Only px units are supported for now.

  • width/height
  • background-color, color
  • font-size, font-family, font-weight, font-style, content, text-align
  • margin
  • padding
  • * selector
  • border, border-radius, border-color, border-width, border-style
  • multiple selectors

Dependencies

  • cairo

Usage

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 = "Hello world!"; // Set content of body to "Hello world!"

let images = render(styles).unwrap(); // Returns a hashmap of css selector -> Image

Dependencies

~4–6MB
~116K SLoC