#!/usr/bin/php * @copyright (c) 2014 by Ralf Becker * @version $Id$ */ if (php_sapi_name() !== 'cli') die("This is a commandline ONLY tool!\n"); $args = $_SERVER['argv']; $prog = array_shift($args); if ($_SERVER['argc'] <= 1 || $prog != 'pixelegg/stylesheet2svg.php') die(" Usage: pixelegg/stylesheet2svg [-s stylesheet] svg-image(s) Add an external stylesheet to an svg image and sets id of svg tag to app_image Examples: - pixelegg/stylesheet2svg -s pixelegg/less/svg.css */templates/pixelegg/images/*.svg pixelegg/images/*.svg \n"); $stylesheet = 'pixelegg/less/svg.css'; if ($args[0] == '-s') { $stylesheet = $args[1]; array_shift($args); array_shift($args); } foreach($args as $path) { if (!preg_match('|^([^/]+)/.*/(.*).svg$|', $path, $matches) || !($svg = file_get_contents($path))) { error_log("SVG image $path NOT found or empty!\n"); continue; } // remove evtl. existing old stylesheet $svg = preg_replace("|<\\?xml-stylesheet[^?]+\\?>\n?|", '', $svg); // add stylesheet $style_url = rel_path($stylesheet, $path); $svg = preg_replace('|'."\n".' $i_part) { if (isset($s_parts[$n]) && $s_parts[$n] === $i_part) { array_shift($rel_parts); } else { array_unshift($rel_parts, '..'); } } $rel_path = implode('/', $rel_parts); //error_log(__FUNCTION__."($stylesheet, $image) returned $rel_path"); return $rel_path; }