forked from phpmyadmin/phpmyadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-sprites
executable file
·148 lines (134 loc) · 4.09 KB
/
generate-sprites
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/sh
# vim: expandtab sw=4 ts=4 sts=4:
# Check for proper number of command line args.
if [ $# -ne 1 ]; then
echo "Usage: `basename $0` {path_to_pma_root_folder}"
exit 65
fi
# Check if we have ImageMagick
hash identify 2>&- || {
echo "ERROR: ImageMagick not found on the system!"
echo "Quitting..."
exit 1
}
# Compress image, if possible
HAVE_PNGCRUSH=1
hash pngcrush 2>&- || {
HAVE_PNGCRUSH=0
echo "WARNING: 'pngcrush' not found, will not be able to compress the sprites"
}
# Icons that should not be included in the sprite
BLACKLIST="vertical_line.png spacer.png"
# Output filename for the sprite image
OUTPUT="sprites.png"
# Library file that will contain the information about
# individual images that are part of the sprite
LIBRARY="../sprites.lib.php"
if [ -d $1/themes ]; then
cd $1/themes
# For each theme
for d in $(ls -d */); do
# Go to folder that contains the images
cd "$d"img
echo "Processing folder: $PWD"
FILES=''
for f in $(ls *.png| LC_ALL=C sort); do
VALID=true
# Do not include blacklisted icons
for b in $BLACKLIST; do
if [ "$b" = "$f" ]; then
VALID=false
fi
done
if [ $VALID = false ]; then
continue
fi
DATA=$(identify -ping $f || echo "NULL")
if [ "$DATA" != "NULL" ]; then
SIZE=$(echo $DATA | cut -d ' ' -f 3 | sed 's/x/ /')
# Do not include icons that are larger than 16x16
for s in $SIZE; do
if [ $s -gt 16 ]; then
VALID=false
fi
done
if [ $VALID = true ]; then
# Build the list of valid icons
FILES="$FILES $f"
fi
fi
done
# Create an empty sprite of the correct size
NUM_FILES=''
for f in $FILES; do
NUM_FILES=$(($NUM_FILES+1))
done
convert -size 16x$(($NUM_FILES*16+16)) xc:none temp.png
# Add each icon to the sprite
CURRENT=1
for f in $FILES; do
convert temp.png $f -geometry +0+$(($CURRENT*16)) -composite temp.png
CURRENT=$(($CURRENT+1))
done
# Compress image, if possible
if [ $HAVE_PNGCRUSH -eq 1 ]; then
echo "Compressing file: $PWD/$OUTPUT"
pngcrush -brute temp.png $OUTPUT > /dev/null
rm -f temp.png
else
mv temp.png $OUTPUT
fi
# Generate the library file that contains the information
# about individual images that are part of the sprite
echo '<?php' > $LIBRARY
echo '/**' >> $LIBRARY
echo ' * AUTOGENERATED CONTENT - DO NOT EDIT!' >> $LIBRARY
echo ' * ALL CHANGES WILL BE UNDONE!' >> $LIBRARY
echo ' * RUN `./scripts/generate-sprites` TO UPDATE THIS FILE' >> $LIBRARY
echo ' *' >> $LIBRARY
echo ' * @package PhpMyAdmin-theme' >> $LIBRARY
echo ' */' >> $LIBRARY
echo '' >> $LIBRARY
echo '/**' >> $LIBRARY
echo ' * Returns map of sprites inside sprite.png' >> $LIBRARY
echo ' *' >> $LIBRARY
echo ' * @return array Data of sprites' >> $LIBRARY
echo ' */' >> $LIBRARY
echo "function PMA_sprites()" >> $LIBRARY
echo "{" >> $LIBRARY
echo " return array(" >> $LIBRARY
CURRENT=1
for f in $FILES; do
# Add a CSS rule for each icon in the sprite
NAME=$(echo "'$f'" | sed 's/\.png//')
DATA=$(identify -ping $f || echo "NULL")
if [ "$DATA" != "NULL" ]; then
SIZE=$(echo $DATA | cut -d ' ' -f 3 | sed 's/x/ /')
WIDTH=0
HEIGHT=0
for s in $SIZE; do
if [ $WIDTH = 0 ]; then
WIDTH=$s
else
HEIGHT=$s
fi
done
fi
echo " $NAME => array(" >> $LIBRARY
echo " 'position' => '$CURRENT'," >> $LIBRARY
echo " 'width' => '$WIDTH'," >> $LIBRARY
echo " 'height' => '$HEIGHT'" >> $LIBRARY
echo " )," >> $LIBRARY
CURRENT=$(($CURRENT+1))
done
echo " );" >> $LIBRARY
echo "}" >> $LIBRARY
echo "?>" >> $LIBRARY
# Back to the parent folder
cd ../..
done
exit 0
else
echo "ERROR: could not find the 'themes' folder in '`readlink -f $1`'"
exit 1
fi