WangYuLue / image-conversion

A simple and easy-to-use JS image convert tools, which can specify size to compress the image.
https://demo.wangyulue.com/image-conversion/
MIT License
909 stars 140 forks source link

Image not defined in method: dataURLtoImage() #62

Open SugarRayLua opened 6 months ago

SugarRayLua commented 6 months ago

Describe the bug A clear and concise description of what the bug is.

"Image not defined" error when trying to run a simple dataURLtoImage() conversion in node.js

To Reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

See test.js script in node.js below:

const test = require("image-conversion");
var data = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAALtJREFUOE9jXHXs/38GJBBmxYjMxWCvOoainIER2QBCmmGmIRsCNwBZs4qKCsOdO3cY0Glk58AMob4BR9c34w0D68BasDyGC6RftjCAJGEGEGI/Fa8BGwT3AroBuJwBMxjDAFAggmxHthmfIVgDUSzgKMOrDdZwb2AzAGQBzmiEGYAvFAkmJJAh+ADIhVhdANMECgt0QyaEPWQoWCUP9h7MlRhhgM8AmBxVDIDFFNkuQE6FKAkJ2QukxAIAO2u38XQweIsAAAAASUVORK5CYII=";
async function dataURLtoFile(dataURL){
    var image = await test.dataURLtoImage(dataURL);
    return image;
}
var finalImage = dataURLtoFile(data);

Expected behavior A clear and concise description of what you expected to happen.

I didn't expect any errors with this simple script

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

I'm a novice node.js user and apologize if I'm not understanding something basic about how image-conversion works. I'm hoping to use it both on node.js side and on client side browser (through loading through script).

Additionally, if could suggest once I get image-conversion working on my system, how I might easiest then convert the Image back to an image file and store as a local .jpeg file (e.g. store var finalImage in my script above), I'd appreciate it.

Thanks!