1use crate::parsers::ParseErr;
2
3use std::path::Path;
4use imagesize::{size, ImageSize};
5
6
7#[derive(Debug, Clone, Copy)]
8pub struct ImgSize {
9 pub width: u32,
10 pub height: u32,
11}
12
13impl ImgSize {
14 pub fn new(width: u32, height: u32) -> Self {
15 ImgSize { width, height }
16 }
17}
18
19impl From<ImageSize> for ImgSize {
20 fn from(image_size: ImageSize) -> Self {
21 ImgSize { width: image_size.width as u32, height: image_size.height as u32 }
22 }
23}
24
25impl ImgSize {
26 pub fn from_file<P: AsRef<Path>>(path: P) -> Result<ImgSize, ParseErr> {
27 size(path)
28 .map_err(|_| ParseErr {})
29 .map(Into::into)
30 }
31}