build script: use git for fteqcc
[divverent/nexuiz.git] / misc / tools / jpeg-if-not-alpha.sh
1 #!/bin/sh
2
3 set -e
4
5 : ${qual:=95}
6
7 for X in "$@"; do
8         case "$X" in
9                 *.jpg)
10                         if [ -n "$scaledown" ]; then
11                                 mogrify -geometry "$scaledown>" -quality 100 "$X"
12                         fi
13                         jpegoptim --strip-all -m$qual "$X"
14                         ;;
15                 *.png|*.tga)
16                         if [ -n "$scaledown" ]; then
17                                 mogrify -geometry "$scaledown>" -quality 100 "$X"
18                         fi
19                         if convert "$X" -depth 16 RGBA:- | perl -e 'while(read STDIN, $_, 8) { substr($_, 6, 2) eq "\xFF\xFF" or exit 1; ++$pix; } exit not $pix;'; then
20                                 echo "$X has no alpha, converting"
21                                 convert "$X" -quality 100 "${X%.*}.jpg"
22                                 jpegoptim --strip-all -m$qual "${X%.*}.jpg"
23                                 rm -f "$X"
24                         else
25                                 echo "$X has alpha, not converting"
26                         fi
27                         ;;
28         esac
29 done