Created
September 13, 2016 07:46
-
-
Save panayotoff/67f4d35b07d5ad3345bcc6b60880d995 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
exportImage(event) { | |
event.stopPropagation(); | |
this.ctx.fillStyle = "#333333"; | |
this.ctx.font = 'bold 16px Helvetica, Arial, sans-serif'; | |
this.ctx.textBaseline = "top"; | |
var textSize = this.ctx.measureText("esimov.com"); | |
//this.ctx.fillText("esimov.com", this.size - textSize.width - 10, 5); | |
//retrieve canvas image as data URL: | |
var dataURL = this.canvas.toDataURL("image/png"); | |
//open a new window of appropriate size to hold the image: | |
var imageWindow = window.open("", "DeJongAttractor", "left=0,top=0,width=" + this.size + ",height=" + this.size + ",toolbar=0,resizable=0"); | |
//write some html into the new window, creating an empty image: | |
imageWindow.document.write("<title>DeJong Attractor</title>"); | |
imageWindow.document.write("<img id='exportImage'" | |
+ " alt=''" | |
+ " height='" + this.size + "'" | |
+ " width='" + this.size + "'" | |
+ " style='position:absolute;left:0;top:0'/>"); | |
imageWindow.document.close(); | |
//copy the image into the empty img in the newly opened window: | |
var exportImage = imageWindow.document.getElementById("exportImage"); | |
exportImage.src = dataURL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment