Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRouslan Placella <rouslan@placella.com>2011-09-26 23:46:28 +0400
committerRouslan Placella <rouslan@placella.com>2011-09-26 23:46:28 +0400
commit1431d02c8f2b3b45f2b4640bb1ef887ae2e47a0f (patch)
treed2eaa39592a7775b94a53f4fdce389f67ad20607 /scripts
parentcecf7f9fea2964522cc9a4ab1ba85b4beee91a2b (diff)
Made PMA aware of the presence of sprites + added a script for generating sprites from icons
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/create-release.sh5
-rwxr-xr-xscripts/generate-sprites140
2 files changed, 145 insertions, 0 deletions
diff --git a/scripts/create-release.sh b/scripts/create-release.sh
index d411a67e0e..92276168da 100755
--- a/scripts/create-release.sh
+++ b/scripts/create-release.sh
@@ -133,6 +133,11 @@ if [ -f ./scripts/compress-js ] ; then
rm -rf sources
fi
+if [ -f ./scripts/generate-sprites ] ; then
+ echo "* Generating sprites"
+ ./scripts/generate-sprites . || exit 1
+fi
+
echo "* Removing unneeded files"
# Remove test directory from package to avoid Path disclosure messages
diff --git a/scripts/generate-sprites b/scripts/generate-sprites
new file mode 100755
index 0000000000..6ea9aef10c
--- /dev/null
+++ b/scripts/generate-sprites
@@ -0,0 +1,140 @@
+#!/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); 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 "/* AUTOGENERATED CONTENT - DO NOT EDIT */" >> $LIBRARY
+ echo "/* ALL CHANGES WILL BE UNDONE */" >> $LIBRARY
+ echo "/* RUN './scripts/generate-sprites' TO UPDATE THIS FILE */" >> $LIBRARY
+ echo "function PMA_sprites() {" >> $LIBRARY
+ echo " return array(" >> $LIBRARY
+ PADDING=0
+ for f in $FILES; do
+ if [ ${#f} -gt $PADDING ]; then
+ PADDING=${#f}
+ fi
+ done
+ PADDING=$(($PADDING-3))
+ CURRENT=1
+ for f in $FILES; do
+ # Add a CSS rule for each icon in the sprite
+ NAME=$(echo "'$f'" | sed 's/\.png//' | sed -e :a -e "s/^.\{1,$PADDING\}$/& /;ta")
+
+ 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('position' => '$CURRENT', 'width' => '$WIDTH', 'height' => '$HEIGHT')," >> $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