From 7972c6a5d63c0d60f8191a58d324fc0def7ff12b Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Mon, 28 Jun 2021 17:29:36 +0000 Subject: [PATCH] fix #4560 @3 --- composer.json | 3 ++- .../twofaces/class.ws.html5.compiler.php | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e7f336605..f8bb31ba3 100644 --- a/composer.json +++ b/composer.json @@ -3,6 +3,7 @@ "php": ">=7.2", "php-mime-mail-parser/php-mime-mail-parser": "2.11.1", "jaybizzle/crawler-detect": "^1.2", - "ext-mbstring": "*" + "ext-mbstring": "*", + "ext-simplexml": "*" } } diff --git a/inc/ws/Util/html5/twofaces/class.ws.html5.compiler.php b/inc/ws/Util/html5/twofaces/class.ws.html5.compiler.php index 23f38b0d9..a65986f97 100644 --- a/inc/ws/Util/html5/twofaces/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/twofaces/class.ws.html5.compiler.php @@ -2668,9 +2668,35 @@ height="0" width="0" style="display:none;visibility:hidden"> $dest = $dest; } + if (stripos($source, '.svg') !== false) { + $source = $this->_fixSVG($source); + } + $this->vdir->copy($source, $dest); } + protected function _fixSVG($source) + { + $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)); + $attr = $svg->attributes(); + if (isset($attr['width'], $attr['height'])) { + copy($source, $fixed); + return $fixed; + } + + $dim = CubeIT_Image::getimagesize($source); + $svg->addAttribute('preserveAspectRatio', 'none'); + $svg->addAttribute('width', $dim[0]); + $svg->addAttribute('height', $dim[1]); + file_put_contents($fixed, $svg->asXML()); + + return $fixed; + } + public function addVideoJs() { $locale = $this->book->lang; -- 2.39.5