Ticket #2823: fix.sh

File fix.sh, 908 bytes (added by elexis, 9 years ago)

This script uses image magick to remove transparent colored pixels automatically.

Line 
1#!/bin/bash
2#
3# Identifies all png's in the current directory that contain transparent,colored pixels (which can be problematic).
4# See http://trac.wildfiregames.com/ticket/2823
5#
6# requires 'idenify' of the image magick commandline tool http://www.imagemagick.org/script/identify.php
7# available on debian and ubuntu via sudo apt-get install imagemagick
8
9for filename in *.png; do
10
11 # first grep for histogram lines, like
12 # 26: ( 2, 1, 1, 0) #02010100 srgba(2,1,1,0)
13 # then extract text of each line between the sixth = last comma and the first parenthesis after that
14 for alpha in `identify -verbose $filename | grep 'srgba(' | cut -d ',' -f 7 | cut -d ')' -f 1`; do
15
16 if [ "$alpha" == "0" ]
17 then
18 echo "Fixing $filename"
19 mv $filename "${filename}_old.png";
20 convert "${filename}_old.png" -fx 'a==0 ? 0 : u' "$filename";
21 continue 2;
22 fi
23
24 done
25
26 #echo "$filename is ok.";
27done