From c43287b099c6415c010e83398949386e9efe98ba Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Wed, 22 Mar 2017 19:01:19 +0000 Subject: [PATCH] done #1255 @1 --- inc/ws/Util/class.ws.tools.php | 40 +++++++++++++++---- inc/ws/Util/html5/class.ws.html5.compiler.php | 2 +- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/inc/ws/Util/class.ws.tools.php b/inc/ws/Util/class.ws.tools.php index da540dc65..9b08cdce7 100644 --- a/inc/ws/Util/class.ws.tools.php +++ b/inc/ws/Util/class.ws.tools.php @@ -50,7 +50,7 @@ class wsTools { $webvideo->execute(); } - public static function colorizeAndRasterizeIcon($iconSet, $icon, $colors, $dest, &$w, &$h) { + public static function colorizeAndRasterizeIcon($iconSet, $icon, $colors, $dest, $scale, &$w, &$h, $makepng = true) { // Init directory if (is_string($colors)) { $colors = array('colorize' => $colors); @@ -81,8 +81,11 @@ class wsTools { if (!file_exists($dirColorized)) { mkdir($dirColorized, 0777, true); } + + // SVG - if (!file_exists($svgColorized) || filemtime($svgColorized) <= filemtime($svgRef)) { + $time=max(filemtime(__FILE__),filemtime($svgRef)); + if (!file_exists($svgColorized) || filemtime($svgColorized) <= $time) { $svg = file_get_contents($svgRef); // Colorize it foreach ($colors as $k => $v) { @@ -103,11 +106,34 @@ class wsTools { } self::copy($svgColorized, $dest . '/' . $icon . '.svg'); - $svg = simplexml_load_file($svgColorized); - $w = (string)$svg['width']; - $h = (string)$svg['height']; - $w = rtrim($w, 'px'); - $h = rtrim($h, 'px'); + // PNG + $png = $dirColorized . '/' . $icon . '.png'; + $time=max(filemtime(__FILE__),filemtime($svgColorized)); + if (!file_exists($png) || filemtime($png) <= $time) { + $svg = simplexml_load_file($svgColorized); + $w = (string)$svg['width']; + $h = (string)$svg['height']; + $w = rtrim($w, 'px'); + $h = rtrim($h, 'px'); + // Finally rasterize it + $batik = new cubeCommandLine('inkscape'); + $batik->setArg('z'); + $batik->setArg('e', $png); + $batik->setArg('w', $w * $scale); + $batik->setArg('h', $h * $scale); + $batik->setManualArg($svgColorized); + $batik->execute(); + } + + if (file_exists($png)) { + $dim = getimagesize($png); + $w = $dim[0] / $scale; + $h = $dim[1] / $scale; + } + + if ($makepng) { + self::copy($png, $dest . '/' . $icon . '.png'); + } } public static function copy($source, $dest) { diff --git a/inc/ws/Util/html5/class.ws.html5.compiler.php b/inc/ws/Util/html5/class.ws.html5.compiler.php index 6ff24d0ff..97b240b2f 100644 --- a/inc/ws/Util/html5/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/class.ws.html5.compiler.php @@ -1038,7 +1038,7 @@ class wsHTML5Compiler { $this->config->iconsDimensions = array(); $makepng = !$this->supportSVG(); foreach ($icons as $icon => $color) { - wsTools::colorizeAndRasterizeIcon($this->theme->parametres->iconSet, $icon, $color, $this->vdir . '/data/images/', $w, $h); + wsTools::colorizeAndRasterizeIcon($this->theme->parametres->iconSet, $icon, $color, $this->vdir . '/data/images/', 4, $w, $h); $this->config->iconsDimensions[$icon] = array($w, $h); } return $res; -- 2.39.5