Created
January 12, 2019 04:21
-
-
Save mscoutermarsh/b0627a9e96820551844fea46c85bdd1c to your computer and use it in GitHub Desktop.
HTML/CSS to Image. JavaScript example (browser) https://htmlcsstoimage.com
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
var data = new FormData(); | |
data.append('html', "<div class='box'>Success ✅</div>"); | |
data.append('css', ".box { border: 4px solid #03B875; padding: 20px; font-family:'Roboto';}"); | |
data.append('google_fonts', 'Roboto'); | |
var xhr = new XMLHttpRequest(); | |
xhr.open('POST', 'https://hcti.io/v1/image', true); | |
// Retrieve your api_id and api_key from the Dashboard. https://htmlcsstoimage.com/dashboard | |
xhr.setRequestHeader("Authorization", "Basic " + btoa("api_id:api_key")); | |
xhr.onload = function () { | |
var response = JSON.parse(this.responseText) | |
if (response["url"]) { | |
alert(JSON.parse(this.responseText)["url"]); | |
} else { | |
alert(this.responseText); | |
} | |
}; | |
xhr.send(data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment