Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replacing ImageFormat::PNG to ImageFormat::Png in tutorial code #59

Merged

Conversation

shunsock
Copy link
Contributor

Issue

The tutorial code in the README.md of charming contains an incorrect usage of the ImageFormat enum from the image crate. The enum variant ImageFormat::PNG should be ImageFormat::Png.

Solution

The solution involves updating the README.md file to reflect the correct enum variant. The incorrect instances of ImageFormat::PNG have been replaced with ImageFormat::Png.

Changes Made

Replaced ImageFormat::PNG with ImageFormat::Png in the tutorial code for ImageRenderer.

Updated Code

// Use HtmlRenderer.
use charming::HtmlRenderer;

// Chart dimension 1000x800.
let renderer = HtmlRenderer::new("my charts", 1000, 800);
// Render the chart as HTML string.
let html_str = renderer.render(&chart).unwrap();
// Save the chart as HTML file.
renderer.save(&chart, "/tmp/chart.html").unwrap();


// Use ImageRenderer. The `ssr` feature needs to be enabled.
use charming::{ImageRenderer, ImageFormat};

// Chart dimension 1000x800.
let mut renderer = ImageRenderer::new(1000, 800);
// Render the chart as SVG string.
renderer.render(&chart).unwrap();
// Render the chart as PNG bytes.
renderer.render_format(ImageFormat::Png, &chart).unwrap();
// Save the chart as SVG file.
renderer.save(&chart, "/tmp/chart.svg").unwrap();
// Save the chart as PNG file.
renderer.save_format(ImageFormat::Png, &chart, "/tmp/chart.png").unwrap();


// Use WasmRenderer. The `wasm` feature needs to be enabled.
use charming::WasmRenderer;

// Chart dimension 1000x800.
let renderer = WasmRenderer::new(1000, 800);
// Render the chart in the WebAssembly runtime
renderer.render(&chart).unwrap();

Documentation

The README.md file has been updated to ensure correct usage of ImageFormat enum variants, providing accurate guidance for users following the tutorial.

Reference

I checked image::ImageFormat by docs rs and found implementation for it.

/// An enumeration of supported image formats.
/// Not all formats support both encoding and decoding.
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
#[non_exhaustive]
pub enum ImageFormat {
    /// An Image in PNG Format
    Png,

    /// An Image in JPEG Format
    Jpeg,

    /// An Image in GIF Format
    Gif,

    /// An Image in WEBP Format
    WebP,

    // and so on ...
}

@shunsock shunsock changed the title replace ImageFormat::PNG to ImageFormat::Png in tutorial code replacing ImageFormat::PNG to ImageFormat::Png in tutorial code Jun 10, 2024
@yuankunzhang yuankunzhang merged commit 1c33104 into yuankunzhang:main Jun 15, 2024
1 check passed
@shunsock shunsock deleted the fix/image_format_in_tutorial branch June 15, 2024 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants