diff --git a/bin/omarchy-menu-images b/bin/omarchy-menu-images index 6a7443e6..ddf34c25 100755 --- a/bin/omarchy-menu-images +++ b/bin/omarchy-menu-images @@ -74,8 +74,9 @@ fi selection_file=$(mktemp) done_file=$(mktemp) +pending_file=$(mktemp) rm -f "$done_file" -trap 'rm -f "$selection_file" "$done_file"' EXIT +trap 'rm -f "$selection_file" "$done_file" "$pending_file"' EXIT image_dirs_env="" for dir in "${image_dirs[@]}"; do @@ -144,7 +145,8 @@ generate_thumbnail() { local tmp="$thumbnail.$$.jpg" if mkdir "$lock" 2>/dev/null; then - if magick "${image}[0]" -auto-orient -resize '1536x864^' -gravity center -extent '1536x864' -strip -quality 82 "$tmp"; then + # Callers fan out one generator per image, so keep each vips single-threaded. + if VIPS_CONCURRENCY=1 vipsthumbnail "$image" --size 1536x864 --smartcrop=centre --path "$tmp[Q=82,strip]"; then mv -f "$tmp" "$thumbnail" else rm -f "$tmp" "$thumbnail" @@ -186,10 +188,19 @@ thumbnail_for() { return fi - generate_thumbnail "$image" "$thumbnail" + printf '%s\0%s\0' "$image" "$thumbnail" >>"$pending_file" fi - [[ -f $thumbnail ]] && printf '%s' "$thumbnail" + printf '%s' "$thumbnail" +} + +# Generate every queued thumbnail at once; each vips run is single-threaded. +drain_pending_thumbnails() { + [[ -s $pending_file ]] || return 0 + + export -f generate_thumbnail + xargs -a "$pending_file" -0 -n 2 -P "$(nproc)" \ + bash -c 'generate_thumbnail "$1" "$2"' _ >/dev/null 2>&1 || true } if [[ $rows_cache_hit != true && -f $rows_cache_file && -f $rows_signature_file ]] && cmp -s "$rows_signature_file" <(printf '%s' "$rows_signature"); then @@ -210,6 +221,22 @@ elif [[ $rows_cache_hit != true ]]; then fi done + drain_pending_thumbnails + + if [[ -s $pending_file ]]; then + pruned="" + while IFS=$'\t' read -r row_image row_thumbnail; do + [[ -e $row_thumbnail ]] || continue + + if [[ -z $pruned ]]; then + pruned="$row_image"$'\t'"$row_thumbnail" + else + pruned+=$'\n'"$row_image"$'\t'"$row_thumbnail" + fi + done <<<"$rows" + rows="$pruned" + fi + if [[ $rows_cacheable == true ]]; then printf '%s' "$rows" >"$rows_cache_file" printf '%s' "$rows_signature" >"$rows_signature_file" diff --git a/install/omarchy-base.packages b/install/omarchy-base.packages index 44044e7a..5f4a35d8 100644 --- a/install/omarchy-base.packages +++ b/install/omarchy-base.packages @@ -69,6 +69,7 @@ lazydocker lazygit less libsecret +libvips libyaml libreoffice-fresh llvm diff --git a/migrations/1786386460.sh b/migrations/1786386460.sh new file mode 100644 index 00000000..a4d00ace --- /dev/null +++ b/migrations/1786386460.sh @@ -0,0 +1,3 @@ +echo "Generate image picker thumbnails with libvips" + +omarchy-pkg-add libvips