use std::path::Path;
use image::io::Reader as ImageReader;
use image::{ImageBuffer, ImageError, RgbaImage};
use crate::Block;
pub fn from_path(path: &Path) -> Result<Block, ImageError> {
let img = ImageReader::open(path)?.decode()?;
let width = img.width();
let height = img.height();
let bytes = img.into_rgba8().into_vec();
Ok(Block::new(bytes, width, height))
}
pub fn save(block: Block, path: &Path) -> Result<(), ImageError> {
let img: RgbaImage = ImageBuffer::from_vec(block.width, block.height, block.bytes)
.expect("failed to create image buffer");
img.save(path)?;
Ok(())
}