【发布时间】:2015-10-14 11:25:17
【问题描述】:
我正在使用project.exportSVG({asString: true}) 和大量路径(千)。
这需要很长时间,有时脚本会冻结。
而project.exportJSON() 函数则非常快。
我认为这可能是因为 exportSVG 创建了一个 DOM 节点,然后从中生成了一个字符串。因为我只需要字符串,像只适用于字符串的 lite 导出之类的东西会很棒。 有没有办法做到这一点?
我使用 SVG 字符串创建一个 Blob 并通过 https://github.com/eligrey/FileSaver.js/ 保存它
var svg = project.exportSVG({asString: true});
var blob = new Blob([svg], {type: "image/svg+xml;charset=utf-8"});
saveAs(blob, 'test.svg');
这是我在http://sketch.paperjs.org运行的测试脚本
for (var i = 0; i < 1000; i++) {
new Path.Circle({
strokeColor: 'red',
radius: 10,
position: [i, i]
});
}
var t_start, t_end;
t_start = new Date().getTime();
project.exportSVG();
t_end = new Date().getTime();
console.log('svg export: ' + (t_end - t_start));
t_start = new Date().getTime();
project.exportJSON();
t_end = new Date().getTime();
console.log('json export: ' + (t_end - t_start));
【问题讨论】:
标签: performance svg export paperjs