#!/bin/sh # # Check if an image is black & white (bi-level) # MAGIC=/usr/share/misc/magic-mm [ $# -eq 0 ] && { echo "usage: chkbw file ..." >&2; exit 1; } for f in "$@"; do ts="$(file -m $MAGIC "$f")"; t="${ts#*: }" case "$t" in TIFF\ image\ data*) pnmcmd=tifftopnm;; GIF\ image\ data*) pnmcmd=giftoppm;; PNG\ image\ data*) pnmcmd=pngtopnm;; PC\ bitmap\ data*) pnmcmd=bmptopnm;; IFF\ data,\ ILBM*) pnmcmd=ilbmtoppm;; *) case "$1" in *.[Jj][Bb][Gg]) pnmcmd=jbgtopbm;; *.[Pp][Cc][Xx] | *.[Pp[Cc][Cc]) pnmcmd=/usr/local/netpbm/bin/pcxtoppm;; *) echo "chkbw: Unsupported file format" >&2 exit 1;; esac esac hist=$($pnmcmd "$f" 2>/dev/null | ppmhist | wc -l) [ $hist -gt 4 ] && echo "$f: Not B/W" >&2 done .