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

stipple doesn't seem to be supported in non-cli version #23

Closed brubsby closed 3 years ago

brubsby commented 3 years ago

so i have the call to ascii-art:

art.image({
            stippled: true,
            filepath: file,
            threshold: 128,
            width: 32,
            height: 32
          });

and when the art is logged to the console it appears like this: image

and when i save to a file it gets rendered in notepad++ as: image

i'm basically trying to put some stippled ascii art in a subtitle file, fwiw.

windows 10, most recent version of ascii-art on npm.

khrome commented 3 years ago

notepad does not support ansi coloring. NFO readers will, however.

brubsby commented 3 years ago

the colors are cool, but for my current project I am just regex removing them, so that doesn't concern me as much. (and a flag to do no ansi colors would be nice as well)

i'm mostly confused as to why it doesn't seem to use braille with these input settings. to work around it i reverse engineered that i needed these settings:

art.image({
  posterize: true,
  stippled: true,
  background: true,
  filepath: file,
  threshold: 96,
  width: 32,
  height: 32
});

seems like just stippled: true should work

khrome commented 3 years ago

posterize is a special setting which outputs the color to the background and outputs braille characters to get sub-character value accuracy via braille pixels along with full flood coloring. So stippling is already happening, but in black. If I allowed default mode stippling on top of that you'd be setting foreground and background to the same color.

What is the end output effect you want?

Also almost every language has a consise strip-ansi module available. I have recommended this module in the past for a non-ansi mode. Presently all the pixel calculations are done in color and palette reduction logic is expensive... It would be much cheaper to do this in 256 level grey (or thresholded to 2 color).

There are no docs, but you can directly access the braille output here: https://github.com/khrome/ascii-art-braille/blob/master/braille.js

There is also another slightly less detailed sub-character mode, blocks, which may have slightly better support in text editors

khrome commented 3 years ago

Doing some work this week. Is there a feature you wanted out of this other than being able to strip ansi chars?

khrome commented 3 years ago

So after enabling ansi stripping, I finally get what the issue is in the OP. So I fixed the issue and here are some examples of the expected behavior from the upcoming changes (2.6)

art.image({
    filepath: './node_modules/ascii-art-docs/Images/animal_muppet.jpg',
    width: 32,
    height: 32
}, function(err, result){
    console.log(result);
});

Screen Shot 2021-04-15 at 2 07 12 PM

art.image({
    filepath: './node_modules/ascii-art-docs/Images/animal_muppet.jpg',
    width: 32,
    height: 32
}).strip({}, function(err, result){
    console.log(result);
});

Screen Shot 2021-04-15 at 2 08 39 PM

art.image({
    stippled: true,
    filepath: './node_modules/ascii-art-docs/Images/animal_muppet.jpg',
    threshold : 128,
    width: 32,
    height: 32
}, function(err, result){
    console.log(result);
});

Screen Shot 2021-04-15 at 2 31 29 PM

art.image({
    posterized: true,
    stippled: 'black',
    lineart: true,
    blended: true,
    filepath: './node_modules/ascii-art-docs/Images/animal_muppet.jpg',
    threshold : 50,
    width: 32,
    height: 32
}, function(err, result){
    console.log(result);
});

Screen Shot 2021-04-15 at 3 21 10 PM

art.image({
    posterized: true,
    stippled: 'black',
    filepath: './node_modules/ascii-art-docs/Images/animal_muppet.jpg',
    threshold : 20,
    width: 32,
    height: 32
}, function(err, result){
    console.log(result);
});

Screen Shot 2021-04-15 at 3 24 22 PM

These are all slightly different in function. Thanks for catching the defect!

khrome commented 3 years ago

Changes are live.