Created
November 29, 2020 02:21
-
-
Save tpmccallum/92cf7081e2bed550612cdffa6e8dbec9 to your computer and use it in GitHub Desktop.
An example of rotating an image using Rust
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use image::Rgba; | |
use image::ImageBuffer; | |
use image::DynamicImage; | |
use imageproc::geometric_transformations::Interpolation; | |
use image::{ImageOutputFormat, GenericImageView, ImageFormat}; | |
use imageproc::geometric_transformations::rotate_about_center; | |
fn main() { | |
let dyn_img = image::open("/Users/tpmccallum/Documents/cat.png").unwrap(); | |
let (w,h) = dyn_img.dimensions(); | |
println!("W: {:?}", w); | |
println!("H: {:?}", h); | |
let image_bytes = DynamicImage::into_bytes(dyn_img); | |
let image_buffer = ImageBuffer::<Rgba<u8>, Vec<u8>>::from_vec(w, h, image_bytes[..].to_vec()).unwrap(); | |
let rotated_image: ImageBuffer::<Rgba<u8>, Vec<u8>> = rotate_about_center(&image_buffer, 0.45, Interpolation::Nearest, Rgba([255, 0, 0, 0])); | |
rotated_image.save("/Users/tpmccallum/Documents/rotated_cat.png"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment