From 0eaf3cb3224acc87afee0ea33c9e3ea04d981b47 Mon Sep 17 00:00:00 2001 From: Yan Lin Date: Sat, 31 Jan 2026 07:37:13 +0100 Subject: [PATCH] add two image convert functions --- modules/media-process.nix | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/modules/media-process.nix b/modules/media-process.nix index aee39e8..19324cb 100644 --- a/modules/media-process.nix +++ b/modules/media-process.nix @@ -8,6 +8,7 @@ flac unzip p7zip + imagemagick ]; programs.zsh.initContent = '' @@ -54,6 +55,24 @@ shnsplit -f "$cue" -t "%n - %t" -o "$fmt" -d ./tracks "$audio" } + function image2webp() { + local dir="''${1:-.}" + find "$dir" -type f \( -iname '*.png' -o -iname '*.jpg' -o -iname '*.jpeg' \) | while read -r img; do + outfile="''${img%.*}.webp" + ${pkgs.imagemagick}/bin/magick "$img" -resize '1800>' -quality 82 "$outfile" + echo "Converted: $img -> $outfile" + done + } + + function webp2png() { + local dir="''${1:-.}" + find "$dir" -type f -iname '*.webp' | while read -r img; do + outfile="''${img%.*}.png" + ${pkgs.imagemagick}/bin/magick "$img" "$outfile" + echo "Converted: $img -> $outfile" + done + } + function camera-copy() { local delete_source=0 if [[ "$1" == "-d" || "$1" == "--delete" ]]; then