exupero / saveSvgAsPng

Save SVGs as PNGs from the browser.
MIT License
1.09k stars 362 forks source link

Uncaught (in promise) TypeError: Cannot read property 'width' of undefined at saveSvgAsPng.js:265 #241

Open mqsmith opened 4 years ago

mqsmith commented 4 years ago

I am getting an uncaught error. This error is being thrown on the return of the inlineImages promise. I was wondering what it is trying to get the width of. I don't think I have any undefined heights or widths in my SVG.

exupero commented 4 years ago

Strange. The only thing that block of code gets the width of is an Image object it creates (see line 134 here):

        const canvas = document.createElement('canvas');
        const img = new Image();
        img.crossOrigin = 'anonymous';
        img.src = href;
        img.onerror = () => reject(new Error(`Could not load ${href}`));
        img.onload = () => {
          canvas.width = img.width;
          canvas.height = img.height;
          canvas.getContext('2d').drawImage(img, 0, 0);
          image.setAttributeNS('http://www.w3.org/1999/xlink', 'href', canvas.toDataURL('image/png'));
          resolve(true);
        };

img shouldn't be undefined. Can you debug to make sure this is where the error is coming from or get any more details about how?