Translated using Weblate (Slovenian)
[phpmyadmin.git] / scripts / generate-sprites
blob1b8ffb9477640cbe3eeee0894f6e703a41b6f81d
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| LC_ALL=C sort); 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 '/**' >> $LIBRARY
97 echo ' * AUTOGENERATED CONTENT - DO NOT EDIT!' >> $LIBRARY
98 echo ' * ALL CHANGES WILL BE UNDONE!' >> $LIBRARY
99 echo ' * RUN `./scripts/generate-sprites` TO UPDATE THIS FILE' >> $LIBRARY
100 echo ' *' >> $LIBRARY
101 echo ' * @package PhpMyAdmin-theme' >> $LIBRARY
102 echo ' */' >> $LIBRARY
103 echo '' >> $LIBRARY
104 echo '/**' >> $LIBRARY
105 echo ' * Returns map of sprites inside sprite.png' >> $LIBRARY
106 echo ' *' >> $LIBRARY
107 echo ' * @return array Data of sprites' >> $LIBRARY
108 echo ' */' >> $LIBRARY
109 echo "function PMA_sprites()" >> $LIBRARY
110 echo "{" >> $LIBRARY
111 echo " return array(" >> $LIBRARY
112 CURRENT=1
113 for f in $FILES; do
114 # Add a CSS rule for each icon in the sprite
115 NAME=$(echo "'$f'" | sed 's/\.png//')
117 DATA=$(identify -ping $f || echo "NULL")
118 if [ "$DATA" != "NULL" ]; then
119 SIZE=$(echo $DATA | cut -d ' ' -f 3 | sed 's/x/ /')
120 WIDTH=0
121 HEIGHT=0
122 for s in $SIZE; do
123 if [ $WIDTH = 0 ]; then
124 WIDTH=$s
125 else
126 HEIGHT=$s
128 done
130 echo " $NAME => array(" >> $LIBRARY
131 echo " 'position' => '$CURRENT'," >> $LIBRARY
132 echo " 'width' => '$WIDTH'," >> $LIBRARY
133 echo " 'height' => '$HEIGHT'" >> $LIBRARY
134 echo " )," >> $LIBRARY
135 CURRENT=$(($CURRENT+1))
136 done
137 echo " );" >> $LIBRARY
138 echo "}" >> $LIBRARY
139 echo "" >> $LIBRARY
141 # Back to the parent folder
142 cd ../..
143 done
144 exit 0
145 else
146 echo "ERROR: could not find the 'themes' folder in '`readlink -f $1`'"
147 exit 1