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
); 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 "/* 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
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/ /')
112 if [ $WIDTH = 0 ]; then
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))
126 echo " );" >> $LIBRARY
128 echo "?>" >> $LIBRARY
130 # Back to the parent folder
135 echo "ERROR: could not find the 'themes' folder in '`readlink -f $1`'"