namespace Fluidbook\Tools\SVG;
+use Cubist\Util\CommandLine;
use Cubist\Util\CommandLine\Inkscape;
use Cubist\Util\Files\Files;
+use Cubist\Util\Str;
use Fluidbook\Tools\FluidbookTools;
use Illuminate\Validation\Rules\In;
+use ZipStream\File;
class SVGTools {
protected static $_r;
return self::_optimizeSVG($in, $out);
}
- public static function optimizeSVGStr($in, $strokeToPaths = false) {
- $infile = Files::tempnam() . '.svg';
+ public static function optimizeSVGStr($in, $fix = false) {
+
+ $dir = Files::mkdir(sys_get_temp_dir() . '/svgopt');
+
+
+ $infile = Files::tempnam($dir, 'svgopt') . '.svg';
file_put_contents($infile, $in);
- $outfile = Files::tempnam() . '.svg';
+ $outfile = Files::tempnam($dir, 'svgopt') . '.svg';
self::optimizeSVG($infile, $outfile);
- if ($strokeToPaths) {
- self::strokeToPaths($outfile);
- }
- $res = file_get_contents($outfile);
unlink($infile);
+ if ($fix) {
+ $fixed = Files::mkdir(sys_get_temp_dir() . '/svgopt-fixed');
+ self::fix($dir, $fixed);
+ $fixedFile = str_replace($dir, $fixed, $outfile);
+ $res = file_get_contents($fixedFile);
+ unlink($fixedFile);
+ } else {
+ $res = file_get_contents($outfile);
+ }
unlink($outfile);
return $res;
}
return $res;
}
- public static function strokeToPaths($svgfile) {
- $inkscape = new Inkscape();
- $inkscape->strokeToPath($svgfile);
- $inkscape->execute();
+ public static function fix($source, $dest) {
+ $cli = new CommandLine('oslllo-svg-fixer');
+ $cli->setArg('s', $source);
+ $cli->setArg('d', $dest);
+ $cli->execute();
}
}