imgToAscii icon indicating copy to clipboard operation
imgToAscii copied to clipboard

AMD / CommonJS support

Open juanbrujo opened this issue 5 years ago • 3 comments

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

juanbrujo avatar Oct 08 '18 13:10 juanbrujo

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?

victorqribeiro avatar Oct 08 '18 15:10 victorqribeiro

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

juanbrujo avatar Oct 09 '18 14:10 juanbrujo

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.

victorqribeiro avatar Oct 09 '18 19:10 victorqribeiro