How to implement SVG’s preserveAspectRatio=”xMinYMin slice” for canvas drawImage method.

Ken’s answer in the marked as duplicate answer indeed does the same operation as xMinYMin slice if you call it like drawImageProp(ctx, img, 0, 0, canvas.width, canvas.height, 0, 0). But for the ones who want the full implementation of the svg’s preserveAspectRatio attribute, here is one : It does return an object with sx,sy,sw,sh,dx,dy,dw,dh as … Read more

How to save Chart JS charts as image without black background using blobs and filesaver?

If you want a customized background color then, you’d have to draw a background with your preferred color, and you can do so, like this … var backgroundColor=”white”; Chart.plugins.register({ beforeDraw: function(c) { var ctx = c.chart.ctx; ctx.fillStyle = backgroundColor; ctx.fillRect(0, 0, c.chart.width, c.chart.height); } }); DEMO // draw background var backgroundColor=”white”; Chart.plugins.register({ beforeDraw: function(c) { … Read more