question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SVG <img> is massive

See original GitHub issue

Please make sure you are testing with the latest release of html2canvas. Old versions are not supported and issues reported for them will be closed.

Please follow the general troubleshooting steps first:

  • You are using the latest version
  • You are testing using the non-minified version of html2canvas and checked any potential issues reported in the console

Bug reports:

If I use <img src="... .svg"> the svg is super blown up. This appears to only happen with “responsive” svg images (images where no height or width has been set in the actual image encoding). The image and contentBox are rendered with the correct size but the when drawn on the canvas, the image adopts the viewport height.

Here’s the Fiddle: http://jsfiddle.net/1b4mLnfj/2/

screencapture-html2canvas-hertzen-2019-04-10-22_39_56 screencapture-html2canvas-hertzen-2019-04-10-22_40_16

Specifications:

  • html2canvas version tested with: 1.0.0-rc.1 / 1.0.0-rc.0
  • Browser & version: Chrome 73 / Opera 58
  • Operating system: OS X

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:3
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
niklasvhcommented, Apr 12, 2019

Thanks, i’ll look into it

2reactions
wladstoncommented, May 26, 2022

I was able to solve this by setting the width and height attributes in the svg. So in the .svg file source, I changed this:

<svg viewBox="0 0 262 28" fill="none" 

to this

<svg width="262" height="28" viewBox="0 0 262 28" fill="none" 

and it worked!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is my SVG file so big? - Graphic Design Stack Exchange
The SVG file is bigger because it contains more data (in the form of paths and nodes) in comparison to the data contained...
Read more >
SVG icons are very large when inlining the SVG to the HTML ...
The problem is, however, that the icon is showing up extremely large, like over 1000px width and height, causing scrolling and everything. This ......
Read more >
How to optimize and reduce the file size of SVG images
But sometimes complex SVG files can end up with a high file size. In this article, I'm going to break down every possible...
Read more >
How to Scale SVG | CSS-Tricks
Until you open up your web page in test browsers and discover that some leave huge blocks of whitespace above and below the...
Read more >
Category:Large SVG files - Wikimedia Commons
Category:Large SVG files ... This category is intended to collect files causing problems with the show source option of the W3C validator. SVG...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found