+fn image_to_cursor(img: RgbImage, scale: u32) -> Result<Cursor<Vec<u8>>, ImageError> {
+ let (dim_x, dim_y) = img.dimensions();
+ let (dim_x, dim_y) = (dim_x * scale, dim_y * scale);
+
+ // Image must not be larger than 1 megapixel
+ if dim_x * dim_y > 1048576 {
+ return Err(ImageError::dimension_error())
+ }
+
+ let mut cursor = Cursor::new(Vec::new());
+ let img = resize(&img, dim_x, dim_y, FilterType::Nearest);
+ to_imageresult(write_buffer_with_format(&mut cursor, &img, dim_x, dim_y, ColorType::Rgb8, Png))?;
+ Ok(cursor)
+}
+
+