From cb1a0eff50b88ac0990b10be151c879e69ee5388 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 27 Feb 2024 12:03:45 +0100 Subject: [PATCH] wip #6753 @1 --- src/SVG/SVGTools.php | 48 +++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/src/SVG/SVGTools.php b/src/SVG/SVGTools.php index ad3e299..c8cdaf8 100644 --- a/src/SVG/SVGTools.php +++ b/src/SVG/SVGTools.php @@ -6,6 +6,7 @@ use Cubist\Util\CommandLine; use Cubist\Util\Files\Files; use Cubist\Util\PHP; use Fluidbook\Tools\FluidbookTools; +use Illuminate\Support\Facades\Log; class SVGTools { @@ -69,8 +70,31 @@ class SVGTools } copy($in, $beforeOpt); + $cmd = 'timeout -s 1 120 ' . FluidbookTools::tools_path('svgcleaner/svgcleaner', true) . ' ' . $opt . ' --allow-bigger-file --paths-coordinates-precision 3 --copy-on-error --stdout ' . $in; + $svg = shell_exec($cmd); + + Log::debug($cmd); + + if (!$svg) { + $svg = file_get_contents($in); + } + + if (!stristr($svg, 'xmlns="http://www.w3.org/2000/svg"')) { + $svg = str_replace('attributes(); if (!isset($attr['width']) || !isset($attr['height'])) { $viewbox = trim($attr['viewBox']); @@ -81,30 +105,12 @@ class SVGTools if (!isset($attr['height'])) { $xmlsvg->addAttribute('height', (float)$e[3]); } - $tmp = Files::tempnam() . '.svg'; - file_put_contents($tmp, $xmlsvg->asXML()); + return preg_replace('\<\?xml.*\?\>', '', $xmlsvg->asXML()); } } catch (\Exception $e) { } - - $cmd = 'timeout -s 1 120 ' . FluidbookTools::tools_path('svgcleaner/svgcleaner', true) . ' ' . $opt . ' --allow-bigger-file --paths-coordinates-precision 3 --copy-on-error --stdout ' . ($tmp ?? $in); - $svg = shell_exec($cmd); - - if (!$svg) { - $svg = file_get_contents($in); - } - - if (!stristr($svg, 'xmlns="http://www.w3.org/2000/svg"')) { - $svg = str_replace('