cursive-image 0.0.6

Image view for the Cursive TUI library
Documentation
use super::super::{format::*, image::*};

use {
    png::*,
    std::{fs::*, io, path::*},
};

impl Image {
    /// Constructor.
    ///
    /// Gets the image size by decoding the PNG header.
    pub fn new_png_file<PathT>(path: PathT) -> io::Result<Self>
    where
        PathT: AsRef<Path>,
    {
        let path = path.as_ref();
        let mut decoder = Decoder::new(io::BufReader::new(File::open(path)?));
        let info = decoder.read_header_info()?;
        Ok(Self::new_file(path, false, ImageFormat::PNG, (info.width, info.height)))
    }
}