khrome / ascii-art

A Node.js library for ansi codes, figlet fonts, ascii art and other ASCII graphics
MIT License
681 stars 287 forks source link

Error trying to use art.Image #9

Closed cjay567 closed 6 years ago

cjay567 commented 6 years ago

While trying to use art.Image like this:

const art = require('ascii-art');
let image = new art.Image({
    filepath: __dirname + '\\l.jpg',
    alphabet:'hatching'
});

I get this error:

C:\Users\tj\Desktop\TestProjectDoer\node_modules\ascii-art\image.js:109
                ob.canvas = new Canvas(ob.image.width, ob.image.height);
                            ^

TypeError: Canvas is not a constructor
    at C:\Users\tj\Desktop\TestProjectDoer\node_modules\ascii-art\image.js:109:29
    at C:\Users\tj\Desktop\TestProjectDoer\node_modules\ascii-art\image.js:30:17
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:490:3)

I have ascii-art version 1.4.2 and node-canvas version 2.0.0-alpha.11 I have tried rebuilding canvas and reinstalling both modules, so far nothing has worked.

khrome commented 6 years ago

I'll look into this tonight

On Fri, Mar 9, 2018 at 11:47 AM, tjpc3 notifications@github.com wrote:

While trying to use art.Image like this:

const art = require('ascii-art'); let image = new art.Image({ filepath: __dirname + '\l.jpg', alphabet:'hatching' });

I get this error:

C:\Users\tj\Desktop\TestProjectDoer\node_modules\ascii-art\image.js:109 ob.canvas = new Canvas(ob.image.width, ob.image.height); ^

TypeError: Canvas is not a constructor at C:\Users\tj\Desktop\TestProjectDoer\node_modules\ascii-art\image.js:109:29 at C:\Users\tj\Desktop\TestProjectDoer\node_modules\ascii-art\image.js:30:17 at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:490:3)

I have ascii-art version 1.4.2 and node-canvas version 2.0.0-alpha.11 I have tried rebuilding canvas and reinstalling both modules, so far nothing has worked.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/khrome/ascii-art/issues/9, or mute the thread https://github.com/notifications/unsubscribe-auth/AAeLv4a_7Q4kk89Z2MWQM7jXig1ToOOSks5tctw6gaJpZM4SkxnJ .

khrome commented 6 years ago

Is it possible you installed ascii-art before you had canvas' subdependencies and thus the version of canvas installed in ascii-art is broken? (canvas is an optional dependency because some platforms can't build canvas and the library will happily keep running even if it fails). The other possibility is that canvas 2.0 breaks it (I doubt this, as it is browser compatible)

cjay567 commented 6 years ago

It's most likely that canvas' subdependencies are absent in ascii-art. I'll try to recompile it a few more times but in the meantime is there any way to use art.Image without canvas?

cjay567 commented 6 years ago

Update: Got it work. I turned l.jpg into a png and now it loads fine. I can't seem to compile libjpeg-turbo on my machine so canvas got stuck when trying to load jpegs. Since I'm fine with using a png instead of a jpeg I'm going to close this. Thanks for the help.

khrome commented 6 years ago

Awesome, thanks for checking!