From e97bc5a42e83325c74197d7419fdeb41623ea739 Mon Sep 17 00:00:00 2001 From: Emi Simpson Date: Wed, 17 Aug 2022 13:45:26 -0400 Subject: [PATCH] Print a little blurhash for each image --- src/main.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main.rs b/src/main.rs index 7d0b465..ec463a3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -207,6 +207,24 @@ fn download(server: &str, args: DownloadArgs) -> Result<(), AviaryDownloadError> _ => AviaryDownloadError::FilesystemError(e, dest_dir.as_ref().to_owned()), })?; for (indx, image) in index.images.into_iter().enumerate() { + + // Print a little blurhash + const BH_WIDTH: u32 = 12; + const BH_HEIGHT: u32 = 5; + let blur = blurhash::decode(&image.blurhash, BH_WIDTH, BH_HEIGHT, 1.0); + let mut blur = blur.iter(); + for _ in 0..BH_HEIGHT { + for _ in 0..BH_WIDTH { + let r = blur.next().unwrap(); + let g = blur.next().unwrap(); + let b = blur.next().unwrap(); + let _ = blur.next().unwrap(); + print!("\x1b[38;2;{r};{g};{b}m█"); + } + print!("\n"); + } + print!("\x1b[0m"); + let extension = image.format.enum_value().map(|f| match f { Format::PNG => "png", Format::WEBP => "webp",