From 1bc89ddc42c1ab18daaffdad6a9321b310c8f390 Mon Sep 17 00:00:00 2001 From: asonix Date: Fri, 23 Feb 2024 14:13:25 -0600 Subject: [PATCH] Add script for hashing arbitrary files with imagemagick and stdin example --- flake.nix | 1 + scripts/hash.sh | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100755 scripts/hash.sh diff --git a/flake.nix b/flake.nix index 14c7328..855ef82 100644 --- a/flake.nix +++ b/flake.nix @@ -24,6 +24,7 @@ cargo-show-asm clippy imagemagick + jq rust-analyzer rustc rustfmt diff --git a/scripts/hash.sh b/scripts/hash.sh new file mode 100755 index 0000000..88e8fb4 --- /dev/null +++ b/scripts/hash.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +set -e + +if ! [ -f "$1" ]; then + echo "$1" is not a file; + exit 1; +fi + +json=$(magick convert "$1" JSON:-) + +width=$(echo $json | jq '.[0].image.geometry.width') +height=$(echo $json | jq '.[0].image.geometry.height') + +magick convert "$1" RGBA:- | \ + cargo r --example stdin --release -- \ + --width $width \ + --height $height