Last active
August 27, 2020 20:08
-
-
Save john92paul/c9371bf54a36d9714422b3549f085727 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
reader.onloadend = function (e) { | |
var myImage = new Image(); // Creates image object | |
myImage.src = e.target.result; // Assigns converted image to image object | |
myImage.onload = function(ev) { | |
var myCanvas = document.getElementById("myCanvas"); // Creates a canvas object | |
var myContext = myCanvas.getContext("2d"); // Creates a contect object | |
myCanvas.width = myImage.width; // Assigns image's width to canvas | |
myCanvas.height = myImage.height; // Assigns image's height to canvas | |
myContext.drawImage(myImage,0,0); // Draws the image on canvas | |
let imgData = myCanvas.toDataURL("image/jpeg",0.75); // Assigns image base64 string in jpeg format to a variable | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment