fixed stylesheet was added multiple times and no longer break if an images was not found or empty

This commit is contained in:
Ralf Becker 2014-01-15 15:15:47 +00:00
parent 5406f80fd6
commit fef98ac2ed

View File

@ -34,10 +34,11 @@ foreach($args as $path)
{
if (!preg_match('|^([^/]+)/.*/(.*).svg$|', $path, $matches) || !($svg = file_get_contents($path)))
{
die("SVG image $path NOT found!\n");
error_log("SVG image $path NOT found or empty!\n");
continue;
}
// remove evtl. existing old stylesheet
$svg = preg_replace("|<?xml-stylesheet[^?]+?>\n|", '', $svg);
$svg = preg_replace("|<\\?xml-stylesheet[^?]+\\?>\n?|", '', $svg);
// add stylesheet
$style_url = rel_path($stylesheet, $path);
$svg = preg_replace('|<svg|', '<?xml-stylesheet type="text/css" href="'.$style_url.'" ?>'."\n".'<svg', $svg);