Created
February 14, 2016 22:33
-
-
Save zzarcon/1a3603b84dac7abe5e3f 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
var url = 'https://ronreiter-meme-generator.p.mashape.com/meme?meme=Baby+Godfather&font_size=50&font=Impact&top=Thanks+m&bottom=Later'; | |
var headers = new Headers({'X-Mashape-Key': 'API_KEY'}); | |
var options = { | |
method: 'GET', | |
headers: headers, | |
mode: 'cors', | |
cache: 'default' | |
}; | |
var request = new Request(url); | |
fetch(request, options).then((response) => { | |
response.arrayBuffer().then((buffer) => { | |
var base64Flag = 'data:image/jpeg;base64,'; | |
var imageStr = arrayBufferToBase64(buffer); | |
document.querySelector('img').src = base64Flag + imageStr; | |
}); | |
}); | |
function arrayBufferToBase64(buffer) { | |
var binary = ''; | |
var bytes = [].slice.call(new Uint8Array(buffer)); | |
bytes.forEach((b) => binary += String.fromCharCode(b)); | |
return window.btoa(binary); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment