diff --git a/lib/tpl/dokuwiki/images/pagetools-build.php b/lib/tpl/dokuwiki/images/pagetools-build.php new file mode 100644 index 0000000000..1b7262ad54 --- /dev/null +++ b/lib/tpl/dokuwiki/images/pagetools-build.php @@ -0,0 +1,121 @@ + + * @todo Maybe add some more error checking + */ +$GAMMA = 0.8; +$OPTIPNG = '/usr/bin/optipng'; + +// load input images +$input = glob('pagetools/*.png'); +sort($input); +$cnt = count($input); +if(!$cnt){ + die("No input images found. This script needs to be called from within the image directory!\n"); +} + +// create destination image +$DST = imagecreatetruecolor(30,$cnt*45*2); +imagesavealpha($DST, true); +$C_trans = imagecolorallocatealpha($DST, 0, 0, 0, 127); +imagefill($DST, 0, 0, $C_trans); + +// load highlight color from style.ini +$ini = parse_ini_file('../style.ini',true); +$COLOR = hex2rgb($ini['replacements']['__link__']); +$C_active = imagecolorallocate($DST, $COLOR['r'],$COLOR['g'],$COLOR['b']); + +// add all the icons to the sprite image +for($i=0; $i<$cnt; $i++){ + $base = $i*90; + + $IN = imagecreatefrompng($input[$i]); + imagesavealpha($IN, true); + imagecolorscale($IN,$GAMMA); + imagecopy($DST,$IN, 0,$base, 0,0, 30,30); + imagedestroy($IN); + + $IN = imagecreatefrompng($input[$i]); + imagesavealpha($IN, true); + imagecolorscale($IN,$GAMMA); + imagecopy($DST,$IN, 0,$base+45, 0,0, 30,30); + imagedestroy($IN); + + imagelayereffect($DST, IMG_EFFECT_OVERLAY); + imagefilledrectangle($DST, 0,$base+45, 30,$base+45+30, $C_active); + imagelayereffect($DST, IMG_EFFECT_NORMAL); +} + +// output sprite +imagepng($DST,'pagetools-sprite.png'); +imagedestroy($DST); + +// optimize if possible +if(is_executable($OPTIPNG)){ + system("$OPTIPNG -o5 'pagetools-sprite.png'"); +} + +/** + * Convert a hex color code to an rgb array + */ +function hex2rgb($hex) { + // strip hash + $hex = str_replace('#', '', $hex); + + // normalize short codes + if(strlen($hex) == 3){ + $hex = substr($hex,0,1). + substr($hex,0,1). + substr($hex,1,1). + substr($hex,1,1). + substr($hex,2,1). + substr($hex,2,1); + } + + // calc rgb + return array( + 'r' => hexdec(substr($hex, 0, 2)), + 'g' => hexdec(substr($hex, 2, 2)), + 'b' => hexdec(substr($hex, 4, 2)) + ); +} + +/** + * Scale (darken/lighten) a given image + * + * @param ressource $img The truetype GD image to work on + * @param float $scale Scale the colors by this value ( <1 darkens, >1 lightens) + */ +function imagecolorscale(&$img, $scale){ + $w = imagesx($img); + $h = imagesy($img); + + imagealphablending($img, false); + for($x = 0; $x < $w; $x++){ + for($y = 0; $y < $h; $y++){ + $rgba = imagecolorat($img, $x, $y); + $a = ($rgba >> 24) & 0xFF; + $r = ($rgba >> 16) & 0xFF; + $g = ($rgba >> 8) & 0xFF; + $b = $rgba & 0xFF; + + $r = max(min(round($r*$scale),255),0); + $g = max(min(round($g*$scale),255),0); + $b = max(min(round($b*$scale),255),0); + + $color = imagecolorallocatealpha($img, $r, $g, $b, $a); + imagesetpixel($img, $x, $y, $color); + } + } + imagealphablending($img, true); +} + diff --git a/lib/tpl/dokuwiki/images/pagetools-build.sh b/lib/tpl/dokuwiki/images/pagetools-build.sh deleted file mode 100755 index 202e222e98..0000000000 --- a/lib/tpl/dokuwiki/images/pagetools-build.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/sh -# -# This script generates a sprite from the unprocessed toolbar icons by combining them -# and overlaying a color layer for the active state -# -# The final sprite is optimized with optipng -# -# The script currently expects a Linux system with current versions of the imagemagick -# and optipng binaries in the path -# -# @author Andreas Gohr - -OUT=`dirname $0` -IN="$OUT/pagetools" - -if [ ! -d "$IN" ]; then - echo "Input folder $IN not found" - exit 1 -fi - -if [ -z "$TEMP" ]; then - TEMP="/tmp" -fi - -if [ ! -d "$TEMP" ]; then - echo "No temp directory available" - exit 1 -fi - -# add up all images twice -montage `for X in $IN/*.png; do echo -n "$X $X "; done` -background transparent -tile 1x -geometry 30x45 -gravity north $TEMP/icons.png - -# darken the image -convert $TEMP/icons.png \( +clone -fill '#cccccc' -colorize 100% \) -compose multiply -composite $TEMP/darkicons.png - -# create the mask to highlight an active icon -convert -size 30x30 xc:'#2b73b7' -gamma 0.7 $TEMP/active.png - -# create the full mask -montage `for X in $IN/*.png; do echo -n "$TEMP/active.png "; done` -background transparent -tile 1x -geometry 30x60+0+15 -gravity south $TEMP/activemask.png - -# apply mask -convert $TEMP/darkicons.png $TEMP/activemask.png \ -\( -clone 0 -alpha extract \) \ -\( -clone 0 -clone 1 -compose overlay -composite \) \ --delete 0,1 +swap -alpha off -compose copy_opacity -composite $OUT/pagetools-sprite.png - -# optimize final sprite -optipng -o5 $OUT/pagetools-sprite.png - -# remove temporary images -rm -f $TEMP/icons.png -rm -f $TEMP/darkicons.png -rm -f $TEMP/active.png -rm -f $TEMP/activemask.png - diff --git a/lib/tpl/dokuwiki/images/pagetools-sprite.png b/lib/tpl/dokuwiki/images/pagetools-sprite.png index 0e8b4a9bf8..bbd7fd361b 100644 Binary files a/lib/tpl/dokuwiki/images/pagetools-sprite.png and b/lib/tpl/dokuwiki/images/pagetools-sprite.png differ diff --git a/lib/tpl/dokuwiki/images/pagetools.xcf b/lib/tpl/dokuwiki/images/pagetools.xcf deleted file mode 100644 index 034b39a42d..0000000000 Binary files a/lib/tpl/dokuwiki/images/pagetools.xcf and /dev/null differ