Ticket #2823: fix2.sh

File fix2.sh, 2.0 KB (added by elexis, 9 years ago)

This script updates all cursors using image magick and creates a 7zip archive containing the changed files. Execute in trunk directory.

Line 
1#!/bin/bash
2#
3# Identifies and fixes all png's that contain transparent,colored pixels (which can be problematic) and creates a 7z archive with the updated cursors.
4# See http://trac.wildfiregames.com/ticket/2823
5#
6# Requires 'idenify' and 'convert' 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
9# Place the script into 0ad's trunk directory and execute without arguments.
10
11# pngs in the following directories will be updated:
12subdir1=binaries/data/mods/mod/art/textures/cursors/;
13subdir2=binaries/data/mods/public/art/textures/cursors/;
14
15# ------------------------------------------------------------------------------------------------------------
16# Now tell bash to only split the input on newlines:
17# see https://unix.stackexchange.com/questions/9496/looping-through-files-with-spaces-in-the-names
18OIFS="$IFS"
19IFS=$'\n'
20
21filesFixed="";
22
23# check all png's
24for filename in $(find $subdir1 $subdir2 -name *.png); do
25
26 if [[ "$filename" == *_old.png ]]; then
27 continue;
28 fi
29
30 # first grep for histogram lines, like
31 # 26: ( 2, 1, 1, 0) #02010100 srgba(2,1,1,0)
32 # then extract text of each line between the sixth = last comma and the first parenthesis after that
33 for alpha in `identify -verbose "$filename" | grep 'srgba(' | cut -d ',' -f 7 | cut -d ')' -f 1`; do
34
35 if [ "$alpha" == "0" ]
36 then
37 echo "Fixing $filename"
38 mv "$filename" "${filename}_old.png";
39
40 # fix taken from http://www.imagemagick.org/discourse-server/viewtopic.php?t=13746
41 convert "${filename}_old.png" -fx 'a==0 ? 0 : u' "$filename";
42
43 filesFixed="$filesFixed \"$filename\""
44 continue 2;
45 fi
46
47 done
48
49 #echo "$filename does not need to be fixed";
50done
51
52IFS="$OIFS"
53# ------------------------------------------------------------------------------------------------------------
54
55# create a 7zip archive
56if [ "$filesFixed" != "" ]; then
57
58 # delete old file if exists
59 if [ -e "cursors_fixed.7z" ]; then
60 rm "cursors_fixed.7z";
61 fi
62
63 eval "7z a -mx=9 cursors_fixed.7z $filesFixed"
64fi