Print a little blurhash for each image

This commit is contained in:
Emi Simpson 2022-08-17 13:45:26 -04:00
parent b76c812186
commit e97bc5a42e
Signed by: Emi
GPG key ID: A12F2C2FFDC3D847

View file

@ -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",