All pastes #2098749 Raw Edit

find-similar-images

public shellscript v1 · immutable
#2098749 ·published 2012-01-03 23:49 UTC
rendered paste body
#!/bin/bashthis="${0##*/}"diff=$(which puzzle-diff)function usage() {        printf "Usage: $this IMAGE [DIRECTORIES]\n"        printf "Find images in DIRECTORIES that are similar to IMAGE.\n\n"        printf "If a DIRECTORIES is omitted ~/img/chan/ is used by default\n"        exit 100}if [ ${#@} -eq 0 ] ; then        usagefideclare -a dirsreference="$1"shiftif [ ${#@} -gt 0 ] ; then        dirs=("$@")else        dirs=(~/img/chan/)fiif [ ! -f "$reference" ] ; then        printf "$this: '$reference' does not exist or is not a regular file\n"        usagefi# include here a check for image types# what formats does puzzle-diff support?if [ ! -x "$diff" ] ; then        printf "$this requires puzzle-diff, but it was not found in your PATH\n"        exit 101fifind \        "${dirs[@]}"  -type f -not -path '*/x/*' \        \( \                -iname '*.jpg' \                -o \                -iname '*.png' \                -o \                -iname '*.jpeg' \        \) \        -printf "%p: " \        -exec bash -c \                'R=$('"$diff"' "'$reference'" "$1") ; echo $R ' -- {} \        \; \        | sort -r -n -t : -k 2