You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
929 B
55 lines
929 B
4 years ago
|
#!/bin/bash -eu
|
||
|
|
||
|
usage() {
|
||
|
echo >&2 "usage: $0 <input> <output>"
|
||
|
exit 1
|
||
|
}
|
||
|
|
||
|
[[ $# == 2 ]] || usage
|
||
|
FW_INFILE="$1"
|
||
|
FW_OUTFILE="$2"
|
||
|
|
||
|
MIME=`file -b --mime-type "$FW_INFILE"`
|
||
|
|
||
|
case $MIME in
|
||
|
image/gif)
|
||
|
giftopnm "$FW_INFILE" > "$FW_OUTFILE" 2>/dev/null
|
||
|
;;
|
||
|
image/jpeg |\
|
||
|
image/jpg)
|
||
|
jpegtopnm "$FW_INFILE" > "$FW_OUTFILE" 2>/dev/null
|
||
|
;;
|
||
|
image/png)
|
||
|
pngtopnm "$FW_INFILE" > "$FW_OUTFILE" 2>/dev/null
|
||
|
;;
|
||
|
image/x-ms-bmp |\
|
||
|
image/bmp |\
|
||
|
image/x-bmp |\
|
||
|
image/x-bitmap |\
|
||
|
image/x-xbitmap |\
|
||
|
image/x-win-bitmap |\
|
||
|
image/x-windows-bmp |\
|
||
|
image/ms-bmp)
|
||
|
bmptoppm "$FW_INFILE" > "$FW_OUTFILE" 2>/dev/null
|
||
|
;;
|
||
|
*)
|
||
|
echo "Unknown file contents. [$MIME]" >&2
|
||
|
exit 1
|
||
|
;;
|
||
|
esac
|
||
|
|
||
|
MIME2=`file -b --mime-type "$FW_OUTFILE"`
|
||
|
case $MIME2 in
|
||
|
image/x-portable-pixmap |\
|
||
|
image/x-portable-bitmap |\
|
||
|
image/x-portable-greymap)
|
||
|
#temporary file created
|
||
|
;;
|
||
|
*)
|
||
|
echo "Failed to convert file. [$MIME => $MIME2]" >&2
|
||
|
exit 1
|
||
|
;;
|
||
|
esac
|
||
|
|
||
|
exit 0
|