add image rendering progress bar
This commit is contained in:
parent
2ede813a73
commit
933f179328
4 changed files with 80 additions and 4 deletions
67
Cargo.lock
generated
67
Cargo.lock
generated
|
@ -277,6 +277,19 @@ version = "1.0.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990"
|
checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "console"
|
||||||
|
version = "0.15.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "054ccb5b10f9f2cbf51eb355ca1d05c2d279ce1804688d0db74b4733a5aeafd8"
|
||||||
|
dependencies = [
|
||||||
|
"encode_unicode",
|
||||||
|
"libc",
|
||||||
|
"once_cell",
|
||||||
|
"unicode-width 0.2.0",
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cpufeatures"
|
name = "cpufeatures"
|
||||||
version = "0.2.17"
|
version = "0.2.17"
|
||||||
|
@ -352,6 +365,12 @@ version = "1.15.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
|
checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "encode_unicode"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "env_filter"
|
name = "env_filter"
|
||||||
version = "0.1.3"
|
version = "0.1.3"
|
||||||
|
@ -437,7 +456,7 @@ version = "0.2.21"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5"
|
checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"unicode-width",
|
"unicode-width 0.1.14",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -584,6 +603,19 @@ dependencies = [
|
||||||
"hashbrown",
|
"hashbrown",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "indicatif"
|
||||||
|
version = "0.17.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "183b3088984b400f4cfac3620d5e076c84da5364016b4f49473de574b2586235"
|
||||||
|
dependencies = [
|
||||||
|
"console",
|
||||||
|
"number_prefix",
|
||||||
|
"portable-atomic",
|
||||||
|
"unicode-width 0.2.0",
|
||||||
|
"web-time",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "interpolate_name"
|
name = "interpolate_name"
|
||||||
version = "0.2.4"
|
version = "0.2.4"
|
||||||
|
@ -656,6 +688,16 @@ version = "0.3.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f5d4a7da358eff58addd2877a45865158f0d78c911d43a5784ceb7bbf52833b0"
|
checksum = "f5d4a7da358eff58addd2877a45865158f0d78c911d43a5784ceb7bbf52833b0"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "js-sys"
|
||||||
|
version = "0.3.77"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f"
|
||||||
|
dependencies = [
|
||||||
|
"once_cell",
|
||||||
|
"wasm-bindgen",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lazy_static"
|
name = "lazy_static"
|
||||||
version = "1.5.0"
|
version = "1.5.0"
|
||||||
|
@ -822,6 +864,12 @@ dependencies = [
|
||||||
"autocfg",
|
"autocfg",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "number_prefix"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "once_cell"
|
name = "once_cell"
|
||||||
version = "1.21.3"
|
version = "1.21.3"
|
||||||
|
@ -888,6 +936,7 @@ dependencies = [
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"fs_extra",
|
"fs_extra",
|
||||||
"image",
|
"image",
|
||||||
|
"indicatif",
|
||||||
"log",
|
"log",
|
||||||
"mktemp",
|
"mktemp",
|
||||||
"pulldown-cmark",
|
"pulldown-cmark",
|
||||||
|
@ -1485,6 +1534,12 @@ version = "0.1.14"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"
|
checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-width"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "utf8parse"
|
name = "utf8parse"
|
||||||
version = "0.2.2"
|
version = "0.2.2"
|
||||||
|
@ -1606,6 +1661,16 @@ dependencies = [
|
||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "web-time"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb"
|
||||||
|
dependencies = [
|
||||||
|
"js-sys",
|
||||||
|
"wasm-bindgen",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "weezl"
|
name = "weezl"
|
||||||
version = "0.1.8"
|
version = "0.1.8"
|
||||||
|
|
|
@ -13,6 +13,7 @@ clap = { version = "^4.5", features = ["derive"] }
|
||||||
env_logger = "^0.11.8"
|
env_logger = "^0.11.8"
|
||||||
fs_extra = "^1.3.0"
|
fs_extra = "^1.3.0"
|
||||||
image = "^0.25.6"
|
image = "^0.25.6"
|
||||||
|
indicatif = "^0.17.11"
|
||||||
log = "^0.4.27"
|
log = "^0.4.27"
|
||||||
pulldown-cmark = "^0.13.0"
|
pulldown-cmark = "^0.13.0"
|
||||||
rayon = "^1.10.0"
|
rayon = "^1.10.0"
|
||||||
|
|
|
@ -4,6 +4,7 @@ use crate::config::Config;
|
||||||
use album_dir::{AlbumDir, Image};
|
use album_dir::{AlbumDir, Image};
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use image::imageops::FilterType;
|
use image::imageops::FilterType;
|
||||||
|
use indicatif::ProgressBar;
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
|
@ -156,13 +157,14 @@ fn copy_static(config: &Config) -> anyhow::Result<()> {
|
||||||
|
|
||||||
fn generate_images(config: &Config, album: &AlbumDir, full: bool) -> anyhow::Result<()> {
|
fn generate_images(config: &Config, album: &AlbumDir, full: bool) -> anyhow::Result<()> {
|
||||||
let output_path = album.path.join(&config.output_dir);
|
let output_path = album.path.join(&config.output_dir);
|
||||||
// TODO: progress bar ?
|
|
||||||
let mut all_images: Vec<&Image> = album.iter_all_images().collect();
|
let mut all_images: Vec<&Image> = album.iter_all_images().collect();
|
||||||
|
|
||||||
// also resize cover image
|
// also resize cover image
|
||||||
all_images.push(&album.cover);
|
all_images.push(&album.cover);
|
||||||
|
|
||||||
all_images.par_iter().try_for_each(|img| {
|
println!("Generating images...");
|
||||||
|
let progress = ProgressBar::new(all_images.len() as u64);
|
||||||
|
let result = all_images.par_iter().try_for_each(|img| {
|
||||||
let full_size_path = output_path.join(&img.path);
|
let full_size_path = output_path.join(&img.path);
|
||||||
if !full
|
if !full
|
||||||
&& full_size_path.exists()
|
&& full_size_path.exists()
|
||||||
|
@ -171,6 +173,7 @@ fn generate_images(config: &Config, album: &AlbumDir, full: bool) -> anyhow::Res
|
||||||
log::info!("Skipping {}, already generated", img.path.display());
|
log::info!("Skipping {}, already generated", img.path.display());
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
log::info!(
|
log::info!(
|
||||||
"Copying original {} -> {}",
|
"Copying original {} -> {}",
|
||||||
img.path.display(),
|
img.path.display(),
|
||||||
|
@ -209,8 +212,12 @@ fn generate_images(config: &Config, album: &AlbumDir, full: bool) -> anyhow::Res
|
||||||
.resize(config.view_size.0, config.view_size.1, IMG_RESIZE_FILTER)
|
.resize(config.view_size.0, config.view_size.1, IMG_RESIZE_FILTER)
|
||||||
.save(&screen_path)?;
|
.save(&screen_path)?;
|
||||||
|
|
||||||
|
progress.inc(1);
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
});
|
||||||
|
progress.finish();
|
||||||
|
|
||||||
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_html(config: &Config, album: &AlbumDir) -> anyhow::Result<()> {
|
fn generate_html(config: &Config, album: &AlbumDir) -> anyhow::Result<()> {
|
||||||
|
@ -223,6 +230,8 @@ fn generate_html(config: &Config, album: &AlbumDir) -> anyhow::Result<()> {
|
||||||
.ok_or(anyhow!("Missing _templates dir in album dir"))?,
|
.ok_or(anyhow!("Missing _templates dir in album dir"))?,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
println!("Generating HTML...");
|
||||||
|
|
||||||
let mut dir_queue: VecDeque<&AlbumDir> = VecDeque::from([album]);
|
let mut dir_queue: VecDeque<&AlbumDir> = VecDeque::from([album]);
|
||||||
while let Some(album) = dir_queue.pop_front() {
|
while let Some(album) = dir_queue.pop_front() {
|
||||||
let html_path = output_path.join(&album.path).join("index.html");
|
let html_path = output_path.join(&album.path).join("index.html");
|
||||||
|
|
|
@ -5,6 +5,7 @@ use std::path::Path;
|
||||||
|
|
||||||
fn main() -> anyhow::Result<()> {
|
fn main() -> anyhow::Result<()> {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
let album_path = Path::new(&cli.album_path).canonicalize()?;
|
let album_path = Path::new(&cli.album_path).canonicalize()?;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue