Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory Error when dealing with SVGs that are about 150 MB #112

Open
SajanaW opened this issue Aug 21, 2018 · 0 comments
Open

Memory Error when dealing with SVGs that are about 150 MB #112

SajanaW opened this issue Aug 21, 2018 · 0 comments

Comments

@SajanaW
Copy link

SajanaW commented Aug 21, 2018

Hi,
UPDATE: So it works on a Mac but fails on Windows64
so I'm trying to use your library to convert some relatively large SVG files (Between 70MB to 150MB). It seems to be able to handle 50mb files fine. I'm also converting them to pretty large PNGs (4800 by 4250). The code is attached below along with an example SVG you can try. This is the error message I get.

Error:
`Error: Command failed: D:\Slic3rSVGs\node_modules\svg2png\node_modules\phantomjs-prebuilt\lib\phantom\bin\phantomjs.exe D:\Slic3rSVGs\node_modules\svg2png\lib\converter.js {"width":4800,"height":4200}
Memory exhausted.

at ChildProcess.exithandler (child_process.js:275)
at emitTwo (events.js:126)
at ChildProcess.emit (events.js:214)
at maybeClose (internal/child_process.js:925)
at Process.ChildProcess._handle.onexit (internal/child_process.js:209)`

Code:

'const fs = require("pn/fs");
const svg2png = require("svg2png");
const maxPerIteration = 1

async function runExport(files) {
let promiseChunk = []
for (let i = 400; i < files.length; i++) {
console.log('Starting iteration ' + i)
const input = fs.readFileSync(files[i])
const saveName = 'ouput_' + i + '.png'
let svgPromise = svg2png(input, { width: 4800, height: 4200 })
.then(buffer => {
fs.writeFile(saveName, buffer)
if (i+1 == files.length){
var end = new Date().getTime()
console.log((end-seconds)/1000)
}
}).catch(e => console.error(e));
promiseChunk.push(svgPromise);
if (i % maxPerIteration === 0){
await Promise.all(promiseChunk)
}
}
}
`

What have I done to remedy this?
I've increased:
'--max-old-space-size=4096'

I've also looked into the heap using heapsnap shot and it seems it is only using like 350 Mb in these cases. (I could paste these later if it is useful). So I'm not entirely sure what is wrong. Some help would be extremely nice!

The file:
https://drive.google.com/file/d/12dCoTPm3glBfw5oUsvyhmtwWTto4XjR0/view?usp=sharing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant