Skip to main content

cursive_image/image/compatibility/
png.rs

1use super::super::{format::*, image::*};
2
3use {
4    png::*,
5    std::{fs::*, io, path::*},
6};
7
8impl Image {
9    /// Constructor.
10    ///
11    /// Gets the image size by decoding the PNG header.
12    pub fn new_png_file<PathT>(path: PathT) -> io::Result<Self>
13    where
14        PathT: AsRef<Path>,
15    {
16        let path = path.as_ref();
17        let mut decoder = Decoder::new(io::BufReader::new(File::open(path)?));
18        let info = decoder.read_header_info()?;
19        Ok(Self::new_file(path, false, ImageFormat::PNG, (info.width, info.height)))
20    }
21}