Skip to content
Snippets Groups Projects
scale.rs 490 B
Newer Older
Louis's avatar
Louis committed
use image::imageops::FilterType;
use image::{imageops, GenericImage, ImageBuffer, Pixel};

pub fn rescale<T: GenericImage>(
	image: &T,
	factor: f32,
) -> anyhow::Result<ImageBuffer<T::Pixel, Vec<<T::Pixel as Pixel>::Subpixel>>>
where
	T::Pixel: 'static,
	<T::Pixel as Pixel>::Subpixel: 'static,
{
	let nwidth = (image.width() as f32 * factor) as u32;
	let nheight = (image.height() as f32 * factor) as u32;

	Ok(imageops::resize(
		image,
		nwidth,
		nheight,
		FilterType::Nearest,
	))
}