pub fn encode_png(koi_frame: &KoiFrame) -> Result<Vec<u8>, EncodingError>Expand description
Encode a static PNG by repeating each native pixel in both dimensions. Preserve its color and alpha without interpolation, timestamps, I/O, or mutation. Encoding errors propagate before the caller publishes any resulting bytes.
Examples found in repository?
examples/generate-library.rs (line 318)
308fn render_sample(
309 output_directory: &Path,
310 koi_development: &KoiDevelopment,
311 koi_body: KoiBody,
312 file_stem: &str,
313 heading: &str,
314 index_markdown: &mut String,
315) -> Result<KoiFrame, Box<dyn Error>> {
316 let koi_frame = render_koi(koi_development, koi_body);
317 let file_name = format!("{file_stem}.png");
318 write_artifact(output_directory, &file_name, &encode_png(&koi_frame)?)?;
319 let svg_name = format!("{file_stem}.svg");
320 write_artifact(
321 output_directory,
322 &svg_name,
323 encode_svg(&koi_frame).as_bytes(),
324 )?;
325 index_markdown.push_str(&format!(
326 "### {heading}\n\n\n\n[SVG]({svg_name})\n\n"
327 ));
328 Ok(koi_frame)
329}