victorqribeiro / imgToAscii

A JavaScript implementation of a image to Ascii code
https://victorqribeiro.github.io/imgToAscii/
MIT License
400 stars 34 forks source link

AMD / CommonJS support #2

Open juanbrujo opened 6 years ago

juanbrujo commented 6 years ago

Is your feature request related to a problem? Please describe. This could me imported as an module

Describe the solution you'd like Add AMD / CommonJS / ES modules support

victorqribeiro commented 6 years ago

I think I would have to write a different .js for that, don't I?

a simple

if (typeof module !== 'undefined') {
  module.exports = imgToAscii;
}

wouldn't do it, cause Node doesn't don't support Image class, which is fundamental.

From what I've been reading, I would have to import Canvas and then process the image. Am I right?

juanbrujo commented 6 years ago

You can return a base64 and then the user can use ir right to an or output it in or anything else.

victorqribeiro commented 6 years ago

Yeah, but to process the ASCII the algorithm uses a Image and a Canvas object (DOM Element) which node doesn't implement. So I would have to rewrite the code as a module, using fs.read to read the image and then process it, generating the ASCII code.

It could be done. I'll look in to it.

MarketingPip commented 1 month ago

@victorqribeiro - by chance could you do this as ESM and then use node-canvas for fallback in non DOM environments or just by default? Would gladly take this as ESM module.

victorqribeiro commented 1 month ago

@MarketingPip Yep, I can look into using node-canvas