Skip to content

Instantly share code, notes, and snippets.

@joeyklee
Created December 4, 2019 15:39
Show Gist options
  • Save joeyklee/630f6d310015b69bd3b6160e6ad4ac9e to your computer and use it in GitHub Desktop.
Save joeyklee/630f6d310015b69bd3b6160e6ad4ac9e to your computer and use it in GitHub Desktop.
example of converting image to base 64 for use in RunwayML
<html>
<head></head>
<body>
<img src="JL-sq.jpg" alt="" id="joey" />
<script>
const joey = document.querySelector('#joey');
toDataURL('JL-sq.jpg', function(dataUrl) {
const inputs = {
image: dataUrl,
render_factor: 7
};
// console.log(inputs)
fetch('http://localhost:8000/query', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(inputs)
})
.then(response => response.json())
.then(outputs => {
const { image } = outputs;
console.log(image)
joey.src=image;
// use the outputs in your project
});
});
function toDataURL(src, callback) {
var xhttp = new XMLHttpRequest();
xhttp.onload = function() {
var fileReader = new FileReader();
fileReader.onloadend = function() {
callback(fileReader.result);
};
fileReader.readAsDataURL(xhttp.response);
};
xhttp.responseType = 'blob';
xhttp.open('GET', src, true);
xhttp.send();
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment