]> _ Git - cubeextranet.git/commitdiff
done #1255 @1
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Wed, 22 Mar 2017 19:01:19 +0000 (19:01 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Wed, 22 Mar 2017 19:01:19 +0000 (19:01 +0000)
inc/ws/Util/class.ws.tools.php
inc/ws/Util/html5/class.ws.html5.compiler.php

index da540dc65b8caddc75c5e93b8b13dc033d9747ac..9b08cdce7be0dbf6754f8533d98fd4ef657bcea6 100644 (file)
@@ -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) {
index 6ff24d0fffafd7c2cb45a2fffc61bc4b6f86b42a..97b240b2fe64485e4f4f06386fb76c738bd8f6d9 100644 (file)
@@ -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;