How to implement -toDataURL() function in node.js server?

試著忘記壹切 提交于 2019-12-08 13:09:20

问题


I am a newbie using webgl implementation as a dependent module for my project. I am trying to use .toDataURL() function using node-webgl wrapper at server side. But I get an error station .toDataURL() is undefined. For more detail, please have a look at this link: canvas.toDataURL() is not a function - error node-webGL wrapper

Well the current post is definitely not a duplicate. In the post(earlier link shared) I am trying to find an alternative way to access the data of canvas. The goal of this current post is to implement the .toDataURL() function. I am novice in these webgl. Could you please share some links or procedure on how to implement this small function. or Could I access the same function of browser implementation(copy it here), where can I get that?

Any suggestions will definitely be helpful.

Thank You.


回答1:


A data URI consists of:

data:[<media type>][;base64],<data>

All you need to do is concatenate:

  1. a string "data:"
  2. a media type - e.g. "image/jpeg"
  3. a string ";base64,"
  4. Base64 representation of your data

For more info see:

  • https://en.wikipedia.org/wiki/Data_URI_scheme
  • https://en.wikipedia.org/wiki/Base64

There are several modules on npm that can help you generate Base64:

  • https://www.npmjs.com/search?q=base64

This is basically everything that you need to know to implement toDataURL() function.



来源:https://stackoverflow.com/questions/39663059/how-to-implement-todataurl-function-in-node-js-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!