Skip to content

Instantly share code, notes, and snippets.

@ablwr
Created April 22, 2018 18:33
Show Gist options
  • Select an option

  • Save ablwr/c1dc72564c28cba77c480af01f2be439 to your computer and use it in GitHub Desktop.

Select an option

Save ablwr/c1dc72564c28cba77c480af01f2be439 to your computer and use it in GitHub Desktop.
image.rs
extern crate image;
extern crate glob;
use image::GenericImage;
use image::RgbaImage;
use glob::glob;
struct ImageSequence {
images: Vec<RgbaImage>,
}
impl ImageSequence {
fn from_dir() -> ImageSequence {
let mut images = Vec::new();
for dir_entry_result in glob("data/mandelbrot/*.png").expect("failed to read data/mandelbrot") {
let dir_entry = dir_entry_result.expect("failed to unwrap dir entry");
println!("{:?}", dir_entry);
let img = image::open(dir_entry).expect("failed to decode image");
println!("{:?}", img.dimensions());
println!("{:?}", img.color());
images.push(img.to_rgba());
}
ImageSequence {
images: images,
}
}
}
fn main() {
let mut seq = ImageSequence::from_dir();
for (i, image) in seq.images.iter_mut().enumerate() {
for pixel in image.pixels_mut() {
if pixel.data[2] >= 200 {
pixel.data[0] = 0;
pixel.data[1] = 0;
pixel.data[2] = 255;
};
}
println!("manipulated this image {:?}", i)
}
for (i, image) in seq.images.iter().enumerate() {
image.save(format!("data/out/{}.png", i)).expect("failed to save");
println!("successfully saved image # {:?}", i)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment