}
return $res;
}
+
+ /**
+ * @throws \Exception
+ */
+ public static function fixSVGDimensions($source, $preserveAspectRatio = "none")
+ {
+ $fixed = str_replace('.svg', '.f.svg', $source);
+ if (file_exists($fixed) && filemtime($fixed) >= filemtime($source)) {
+ return $fixed;
+ }
+ $svg = simplexml_load_string(file_get_contents($source));
+ if (!$svg) {
+ copy($source, $fixed);
+ return $fixed;
+ }
+ $attr = $svg->attributes();
+ $dim = self::getimagesize($source);
+ if ($preserveAspectRatio) {
+ $svg->addAttribute('preserveAspectRatio', $preserveAspectRatio);
+ }
+ if (!isset($attr['width'], $attr['height'])) {
+ $svg->addAttribute('width', $dim[0]);
+ $svg->addAttribute('height', $dim[1]);
+ }
+ file_put_contents($fixed, $svg->asXML());
+
+ return $fixed;
+ }
}
\ No newline at end of file