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