cursive_image/image/png.rs
1use 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 mut decoder = Decoder::new(io::BufReader::new(File::open(path.as_ref())?));
17 let info = decoder.read_header_info()?;
18
19 Ok(Self::new_file(path.as_ref(), false, ImageFormat::PNG, (info.width, info.height)))
20 }
21}