Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REPL: saving a thumbnail of the rendered area #388

Open
mindrones opened this issue Dec 6, 2018 · 0 comments
Open

REPL: saving a thumbnail of the rendered area #388

mindrones opened this issue Dec 6, 2018 · 0 comments

Comments

@mindrones
Copy link
Member

Usually when we share a REPL example we get a preview like this:

screen shot 2018-12-06 at 19 19 13

which is not very useful/informative of the shared example. We might then capture a thumbnail of the gist in the gist itself.

This might also improve the search experience.

Tentative/Pseudo Implementation

We might try html2canvas:

// https://stackoverflow.com/a/38936042/582995
function dataURLtoFile(dataurl, filename) {
    var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
        bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
    while(n--){
        u8arr[n] = bstr.charCodeAt(n);
    }
    return new File([u8arr], filename, {type:mime});
}

html2canvas(document.querySelector("#render-area"))
.then(canvas => {
    const dataURL = canvas.toDataURL("image/png", 1.0);
    const file = dataURLtoFile(dataURL);
    // upload to the gist
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant