2 # vim: expandtab sw=4 ts=4 sts=4:
4 # Check for proper number of command line args.
6 echo "Usage: `basename $0` {path_to_pma_root_folder}"
10 # Check if we have ImageMagick
11 hash identify
2>&- ||
{
12 echo "ERROR: ImageMagick not found on the system!"
17 # Compress image, if possible
19 hash pngcrush
2>&- ||
{
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
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
38 for d
in $
(ls -d */); do
39 # Go to folder that contains the images
41 echo "Processing folder: $PWD"
43 for f
in $
(ls *.png| LC_ALL
=C
sort); do
45 # Do not include blacklisted icons
46 for b
in $BLACKLIST; do
47 if [ "$b" = "$f" ]; then
51 if [ $VALID = false
]; then
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
59 if [ $s -gt 16 ]; then
63 if [ $VALID = true
]; then
64 # Build the list of valid icons
70 # Create an empty sprite of the correct size
73 NUM_FILES
=$
(($NUM_FILES+1))
75 convert
-size 16x$
(($NUM_FILES*16+16)) xc
:none temp.png
77 # Add each icon to the sprite
80 convert temp.png
$f -geometry +0+$
(($CURRENT*16)) -composite temp.png
81 CURRENT
=$
(($CURRENT+1))
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
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
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
111 echo " return array(" >> $LIBRARY
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/ /')
123 if [ $WIDTH = 0 ]; then
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))
137 echo " );" >> $LIBRARY
139 echo "?>" >> $LIBRARY
141 # Back to the parent folder
146 echo "ERROR: could not find the 'themes' folder in '`readlink -f $1`'"