Skip to main content

render_to_png_with_background

Function render_to_png_with_background 

Source
pub fn render_to_png_with_background(
    chartml: &ChartML,
    yaml: &str,
    width: u32,
    height: u32,
    density: u32,
    background: [u8; 3],
) -> Result<Vec<u8>, RenderError>
Expand description

Render a ChartML YAML spec to PNG bytes (synchronous) with an explicit canvas background color.

Identical to render_to_png except the pixmap is filled with background instead of white. Use this when the PNG will be placed on a non-white surface (e.g. a dark-mode email card) — the theme set on chartml should use matching colors or chart text will be illegible.

§Arguments

  • chartml — configured ChartML instance with renderers registered
  • yaml — ChartML YAML specification string
  • width — chart width in CSS pixels
  • height — chart height in CSS pixels
  • density — DPI (72 = 1x, 144 = 2x for PDF)
  • background — canvas fill color as [r, g, b]