HTML5 Canvas pie chart

Even after searching Google and triple-checking my radians values, etc. I was still having trouble with this, so I have created a jsFiddle for people to play with as a live example and will post the code below as well. (Update: in the fiddle v2, stroke and labels are added also.) var canvas = document.getElementById(“can”); … Read more

Flutter: How would one save a Canvas/CustomPainter to an image file?

You can capture the output of a CustomPainter with PictureRecorder. Pass your PictureRecorder instance to the constructor for your Canvas. The Picture returned by PictureRecorder.endRecording can then be converted to an Image with Picture.toImage. Finally, extract the image bytes using Image.toByteData. Here’s an example: https://github.com/rxlabz/flutter_canvas_to_image

Center (proportional font) text in an HTML5 canvas

You can do this by using measureText var canvas = document.getElementById(“canvas”), ctx = canvas.getContext(“2d”) canvas.width = 400; canvas.height = 200; ctx.fillStyle = “#003300″; ctx.font=”20px sans-serif”; var textString = “Hello look at me!!!”, textWidth = ctx.measureText(textString ).width; ctx.fillText(textString , (canvas.width/2) – (textWidth / 2), 100); Live Demo More elaborate demo

HTML5 Canvas: Get Event when drawing is finished

Like almost all Javascript functions, drawImage is synchronous, i.e. it’ll only return once it has actually done what it’s supposed to do. That said, what it’s supposed to do, like most other DOM calls, is queue-up lists of things to be repainted next time the browser gets into the event loop. There’s no event you … Read more

Convert PDF to a Base64-encoded string in Javascript

Try this :- <input id=”inputFile” type=”file” onchange=”convertToBase64();” /> <script type=”text/javascript”> function convertToBase64() { //Read File var selectedFile = document.getElementById(“inputFile”).files; //Check File is not Empty if (selectedFile.length > 0) { // Select the very first file from list var fileToLoad = selectedFile[0]; // FileReader function for read the file. var fileReader = new FileReader(); var base64; … Read more

HTML5 Canvas get transform matrix?

No, there simply isn’t. 🙁 Most canavs libraries (such as cake.js) have instead implemented their own matrix class to keep track of the current transformation matrix. The creator of cake.js thought that there being no way to get the current matrix was ridiculous enough to warrant a bug report about it. Unfortunately that was back … Read more

tech