Skip to content

Commit

Permalink
Merge branch 'add_gif_support' of https://github.com/calum/terminal_i…
Browse files Browse the repository at this point in the history
…mage_display into add_gif_support
  • Loading branch information
calum committed Apr 25, 2018
2 parents 0c2d976 + 59ec8c8 commit ccb3145
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,28 +153,39 @@ fn render_image(mut image: RgbImage, width: u32, height: u32) {
}

screen.print();
println!("");
}

pub fn display_image(image_filepath: &str, width: u32, height: u32) {
let mut img = get_image(image_filepath);

render_image(img, width, height);
println!("");
}

pub fn display_gif(gif_filepath: &str, width: u32, height: u32) {
// get the original gif
let mut frames = get_gif(gif_filepath);

let mut modified_frames = Vec::new();

// create the new reduced gif by shrinking each frame to fit
// the terminal
for (i, frame) in frames.enumerate() {
let delay = frame.delay().to_integer() as u64;
let mut image = frame.into_buffer();

modified_frames.push((image.clone(), delay));

// display the image:
render_image(image.convert(), width, height);

thread::sleep(time::Duration::from_millis(delay));
}

loop {
for (frame, delay) in modified_frames.clone() {
render_image(frame.clone().convert(), width, height);
thread::sleep(time::Duration::from_millis(delay));
}
}
}

0 comments on commit ccb3145

Please sign in to comment.