Browser crash when trying to convert html + svg to scaled image
See original GitHub issueI am using Treant.js javascript library to create an organisational chart. I used the following code to convert the SVG elements (the lines that connect the boxes) and HTML contents (the boxes):
var useWidth = $( '#orgchart' ).prop( 'scrollWidth' );
var useHeight = $( '#orgchart' ).prop( 'scrollHeight' );
var scaleBy = 5;
var w = useWidth;
var h = useHeight;
var scaledCanvas = document.createElement( 'canvas' );
scaledCanvas.width = w * scaleBy;
scaledCanvas.height = h * scaleBy;
var scaledContext = scaledCanvas.getContext( '2d' );
scaledContext.scale( scaleBy, scaleBy );
html2canvas( $( "#orgchart" ), {
canvas : scaledCanvas,
logging : false,
onrendered : function ( canvas ) {
$( "#orgChartSketchDivBody" ).html( "<canvaS id=\"orgChartSketch\"></canvas>" );
var sketchCanvas = document.getElementById( 'orgChartSketch' );
var sketchContext = sketchCanvas.getContext( '2d' );
sketchCanvas.width = w * scaleBy;
sketchCanvas.height = h * scaleBy;
sketchContext.drawImage( canvas, 0, 0 );
sketchContext.scale( ( w * scaleBy ) / ( h * scaleBy ), ( w * scaleBy ) / ( h * scaleBy ) );
var imgData = sketchCanvas.toDataURL( 'image/png' );
}
} );
This works fine as long as the chart is small. But for large charts, when rendered, the browser freezes and crashes (I am using latest Chrome). I know the scale value 5 is high, but I need high quality images so as to get readable images of large charts. Is there any solution to stop the browser from crashing?
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Browser crash when trying to convert HTML+ SVG content to ...
I know the scale value 5 is high, but I need high quality images so as to get readable images of large charts....
Read more >Browser Crash When Trying To Convert Html+ Svg ... - ADocLib
Scalable Vector Graphics or SVG, is a markup language for creating vector based the HTML, this means the image can still be seen...
Read more >some SVG images hang browser when loaded via data URI
We've found that some images, at least some SVG files, cause Firefox 7.0.1, 8beta, and 9/aurora to hang during this process, while Firefox...
Read more >Raster images inside inline SVG are scaled extremely blurrily
I'm not certain if this is the same issue but we're trying to use SVG's to do image masking. In our case, we...
Read more >A Complete Guide to SVG Fallbacks - CSS-Tricks
To get an image fallback in SVG, without extra downloads, you need a way of including an image: That old browsers will recognize...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @tanzid203, looking at your code I’m a bit confused why you’ve created
sketchCanvas
. If your goal is to getimgData
, you can use.toDataURL()
directly on the canvas given by theonrendered
function. Also, your final scale could simplify tosketchContext.scale(w/h, w/h)
, though I’m not sure the purpose of that scale, since it only affects drawing done on it after the scale.Other than that, I’m not sure about your performance issues, sorry!
This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don’t have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.