HAI 1.2
CAN HAS STDIO?
VISIBLE "HAI WORLD!!!1!"
KTHXBYE
tzvetkoff / im2a Goto Github PK
View Code? Open in Web Editor NEWAn image to ASCII converter, made for 256-color terminals.
License: Other
An image to ASCII converter, made for 256-color terminals.
License: Other
HAI 1.2
CAN HAS STDIO?
VISIBLE "HAI WORLD!!!1!"
KTHXBYE
Currently, im2a generates escape codes for every single pixel.
This could be optimised by comparing each pixel with the previous one and keeping the foreground/background color if it is unchanged.
It would also be nice if pixel pairs with the same color could be turned into a blank character (
) instead of the default ▄
. This would allow setting only the background color.
I set up my linux environment to have all dependencies, but something called "PixelPacket" causes severe errors. Please help me, I really want to use your software on my armhf Raspberry Pi 2, so far I got everything working there.
/im2a/im2a$ sudo make install
Making install in src
make[1]: Entering directory '/home/ubuntu/im2a/im2a/src'
g++ -DHAVE_CONFIG_H -I. -I.. -fopenmp -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -fopenmp -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -fopenmp -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -I/usr/local/include/ImageMagick-7 -g -O2 -MT asciifier.o -MD -MP -MF .deps/asciifier.Tpo -c -o asciifier.o asciifier.cpp
asciifier.cpp: In member function ‘void im2a::Asciifier::asciify()’:
asciifier.cpp:173:5: error: ‘PixelPacket’ is not a member of ‘Magick’
Magick::PixelPacket _pixels = _image->getPixels(0, 0, _image->columns(),
^
asciifier.cpp:173:5: note: suggested alternative:
In file included from /usr/local/include/ImageMagick-7/MagickCore/color.h:21:0,
from /usr/local/include/ImageMagick-7/MagickCore/image.h:21,
from /usr/local/include/ImageMagick-7/MagickCore/draw.h:22,
from /usr/local/include/ImageMagick-7/MagickCore/annotate.h:21,
from /usr/local/include/ImageMagick-7/MagickCore/MagickCore.h:79,
from /usr/local/include/ImageMagick-7/Magick++/Include.h:42,
from /usr/local/include/ImageMagick-7/Magick++.h:10,
from asciifier.h:15,
from asciifier.cpp:19:
/usr/local/include/ImageMagick-7/MagickCore/pixel.h:204:3: note: ‘MagickCore::PixelPacket’
} PixelPacket;
^
asciifier.cpp:173:26: error: ‘pixels’ was not declared in this scope
Magick::PixelPacket *pixels = _image->getPixels(0, 0, image->columns(),
^
asciifier.cpp:191:13: error: ‘PixelPacket’ is not a member of ‘Magick’
Magick::PixelPacket *pixel = pixels + offset;
^
asciifier.cpp:191:13: note: suggested alternative:
In file included from /usr/local/include/ImageMagick-7/MagickCore/color.h:21:0,
from /usr/local/include/ImageMagick-7/MagickCore/image.h:21,
from /usr/local/include/ImageMagick-7/MagickCore/draw.h:22,
from /usr/local/include/ImageMagick-7/MagickCore/annotate.h:21,
from /usr/local/include/ImageMagick-7/MagickCore/MagickCore.h:79,
from /usr/local/include/ImageMagick-7/Magick++/Include.h:42,
from /usr/local/include/ImageMagick-7/Magick++.h:10,
from asciifier.h:15,
from asciifier.cpp:19:
/usr/local/include/ImageMagick-7/MagickCore/pixel.h:204:3: note: ‘MagickCore::PixelPacket’
} PixelPacket;
^
asciifier.cpp:191:34: error: ‘pixel’ was not declared in this scope
Magick::PixelPacket *pixel = pixels + offset;
^
asciifier.cpp:211:32: error: ‘class Magick::Color’ has no member named ‘redQuantum’
pow(color->redQuantum() - gs, 2) +
^
asciifier.cpp:212:32: error: ‘class Magick::Color’ has no member named ‘greenQuantum’
pow(color->greenQuantum() - gs, 2) +
^
asciifier.cpp:213:32: error: ‘class Magick::Color’ has no member named ‘blueQuantum’
pow(color->blueQuantum() - gs, 2)
^
asciifier.cpp:243:36: error: ‘class Magick::Color’ has no member named ‘redQuantum’
pow(color->redQuantum() - pixel->red, 2) +
^
asciifier.cpp:244:36: error: ‘class Magick::Color’ has no member named ‘greenQuantum’
pow(color->greenQuantum() - pixel->green, 2) +
^
asciifier.cpp:245:36: error: ‘class Magick::Color’ has no member named ‘blueQuantum’
pow(color->blueQuantum() - pixel->blue, 2)
^
Makefile:402: recipe for target 'asciifier.o' failed
make[1]: ** [asciifier.o] Error 1
make[1]: Leaving directory '/home/ubuntu/im2a/im2a/src'
Makefile:458: recipe for target 'install-recursive' failed
make: *** [install-recursive] Error 1
configure.ac mentions one should use --with-imagemagick-config=<path>
to specify the location of Magic++-config, but according to m4/imagemagick.m4, it should be --with-magick++-config=<path>
.
This can lead to misleading ./configure
output.
Please fix the corresponding line. Thanks.
Hi,
I decided to do some fuzz-testing on your project with AFL++ as it seemed like an interesting task. I found some issues. I used the octocat picture you used as an example as input for the fuzzer:
AFL++ morphed the file into the one contained in this zip: crash6.zip
If you compile im2a the following way:
Compilation steps
./bootstrap
AFL_USE_ASAN=1 ./configure CC=/usr/bin/afl-gcc CXX=/usr/bin/afl-g++ --enable-debug
make install
and then run it as follows:
im2a -p -g <crash-file>
You will get the following error from ASAN:
Note: I had to comment out the precompiler options #if IMAGEMAGICK_VERSION >= 0x7
for ImageMagick version 7 as my version is below that (as you will see in the Versions section) and otherwise I could not compile im2a with the AFL compilers.
There were some other crashes as well, but they don't seem reproducible outside AFL.
If you would like to fuzz the program yourself, I used the following command:
afl-fuzz -i <folder_containing_input_pic> -o <output_folder> -m none /path/to/im2a -p -g @@
.
Beware, I did not find any issues (save for some timeouts) before an hour had passed. I ran this for a total of 12 hours. ~3000 crashes occurred, but the unique issues were only 7, of which the only manually reproducible one I shared with you.
I used the following versions for OS/software/libraries:
Versions:
im2a: 0.6.2 / commit 8a2111b (current master)
Fuzzer: AFL++ 4.0.0c
OS: Kali Linux 2022.3 (kali-rolling)
ImageMagick: 6.9.11
libncurses: 6.3+20220423-2
In pixel mode, when processing images with an odd number of rows, the last line is filled up with garbage.
It would be better if the default background is used instead - or at least the same color as the other part of the character.
It would be very cool if im2a supported transparency.
Partial transparency will be difficult to do, but 100% transparent areas could be mapped to the default terminal background color using \e[49m
.
It may be necessary to use ▀
and
in addition to ▄
for partial pixels, however.
the following command doesn't work, it won't output with 40 row, same for width
im2a --height=40 --grayscale https://cdn.meme.am/cache/instances/folder668/500x/63425668.jpg
Build log:
$ make
make all-recursive
make[1]: Entering directory '/tmp/im2a'
Making all in src
make[2]: Entering directory '/tmp/im2a/src'
g++ -DHAVE_CONFIG_H -I. -I.. -Wall -g -fno-strict-aliasing -O2 -pthread -g -O2 -MT asciifier.o -MD -MP -MF .deps/asciifier.Tpo -c -o asciifier.o asciifier.cpp
asciifier.cpp: In constructor ‘im2a::Asciifier::Asciifier(im2a::Options*, im2a::TermInfo*, Magick::Image*)’:
asciifier.cpp:183:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
(scale_width != _image->columns() || scale_height != _image->rows())) {
~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
asciifier.cpp:183:59: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
(scale_width != _image->columns() || scale_height != _image->rows())) {
~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
asciifier.cpp: In member function ‘void im2a::Asciifier::asciify()’:
asciifier.cpp:221:23: error: cannot convert ‘MagickLib::PixelPacket* {aka MagickLib::_PixelPacket*}’ to ‘MagickLib::Quantum* {aka short unsigned int*}’ in initialization
_image->rows());
^
asciifier.cpp:237:59: error: ‘class Magick::Image’ has no member named ‘alpha’
bool transparent = _options->transparent() && _image->alpha();
^~~~~
asciifier.cpp:239:9: error: ‘MagickCore’ has not been declared
MagickCore::GetPixelChannelOffset(_image->image(),
^~~~~~~~~~
asciifier.cpp:240:13: error: ‘MagickCore’ has not been declared
MagickCore::AlphaPixelChannel) : -1;
^~~~~~~~~~
asciifier.cpp:24:35: error: ‘MAGICKCORE_QUANTUM_DEPTH’ was not declared in this scope
#define MAGICK_QUANTUM_MAX ((1 << MAGICKCORE_QUANTUM_DEPTH) - 1)
^
asciifier.cpp:243:55: note: in expansion of macro ‘MAGICK_QUANTUM_MAX’
(1.0f - _options->transparency_threshold()) * MAGICK_QUANTUM_MAX;
^~~~~~~~~~~~~~~~~~
asciifier.cpp:24:35: note: suggested alternative: ‘MAGICK_QUANTUM_MAX’
#define MAGICK_QUANTUM_MAX ((1 << MAGICKCORE_QUANTUM_DEPTH) - 1)
^
asciifier.cpp:243:55: note: in expansion of macro ‘MAGICK_QUANTUM_MAX’
(1.0f - _options->transparency_threshold()) * MAGICK_QUANTUM_MAX;
^~~~~~~~~~~~~~~~~~
asciifier.cpp:260:26: error: ‘MagickCore’ has not been declared
offset * MagickCore::GetPixelChannels(_image->image());
^~~~~~~~~~
asciifier.cpp:291:32: error: ‘class Magick::Color’ has no member named ‘quantumRed’
pow(color->quantumRed() - gs, 2) +
^~~~~~~~~~
asciifier.cpp:292:32: error: ‘class Magick::Color’ has no member named ‘quantumGreen’
pow(color->quantumGreen() - gs, 2) +
^~~~~~~~~~~~
asciifier.cpp:293:32: error: ‘class Magick::Color’ has no member named ‘quantumBlue’
pow(color->quantumBlue() - gs, 2)
^~~~~~~~~~~
asciifier.cpp:330:36: error: ‘class Magick::Color’ has no member named ‘quantumRed’
pow(color->quantumRed() - pixel[0], 2) +
^~~~~~~~~~
asciifier.cpp:331:36: error: ‘class Magick::Color’ has no member named ‘quantumGreen’
pow(color->quantumGreen() - pixel[1], 2) +
^~~~~~~~~~~~
asciifier.cpp:332:36: error: ‘class Magick::Color’ has no member named ‘quantumBlue’
pow(color->quantumBlue() - pixel[2], 2)
^~~~~~~~~~~
Makefile:382: recipe for target 'asciifier.o' failed
make[2]: *** [asciifier.o] Error 1
make[2]: Leaving directory '/tmp/im2a/src'
Makefile:411: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/tmp/im2a'
Makefile:331: recipe for target 'all' failed
make: *** [all] Error 2
Sorry to bother you again, but it seems not to work. the same command runs fine with jp2a:
ubuntu@ubuntu:~$ im2a --height=170 test0.jpg
im2a 0.4.0
Convert image files to ASCII art
Copyright (C) 2013 Latchezar Tzvetkoff
Distributed under The Beerware LicenseUsage:
im2a [options]Options:
-h, --help Prints this message
-v, --version Prints version string
-m, --html Output HTML
-i, --invert Invert the image
-t, --center Center the image
-W, --width=N Set output width
-H, --height=M Set output height
-c, --charset=CHARSET Set output charset
-g, --grayscale Grayscale output instead of 256-color
-R, --red-weight=RW Set red component weight (default: 0.2989)
-G, --green-weight=GW Set green component weight (default: 0.5866)
-B, --blue-weight=BW Set blue component weight (default: 0.1145)Project homepage: https://github.com/tzvetkoff/im2a
Report bugs to https://github.com/tzvetkoff/im2a/issues
ubuntu@ubuntu:~$
Could you add support for dithering?
(To avoid flat, unsightly areas that appear in some images after colour reduction.)
Since you're using ImageMagick this should be simple.
PS! Thanks for a nice and simple utility.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.