A command line tool for converting images to ASCII art.
A C++20 compatible compiler is required for this program to function as expected
- Clone this project
git clone https://github.com/Oakamoore/image-to-ascii.git
- Step into the repository
cd image-to-ascii
- Build the project using CMake
# Configure the build
cmake -S . -B build
# Build project binaries
cmake --build build
A build configuration (Debug
, Release
etc.) can also be specified.
To prevent tests from being built, append -D ENABLE_TESTING=0
to the build configuration command.
Once the project is built, navigate to the newly created build directory, image-to-ascii/build/
, and locate the executable.
- Run the program once, to create the
input/
andoutput/
directories (if they do not already exist):
./image-to-ascii
-
Populate the
input/
directory with the images to be converted -
Run the program again, this time supplying command line arguments - in the form of the names of images with their file extensions:
./image-to-ascii apple.png banana.png
If the arguments provided are valid image names, the output/
directory will be populated as follows:
# Place images to be converted here
input/
apple.png
banana.png
# Creates a directory based on the image's file name
# Holds the intermediate conversion steps (defaulted to 'png')
output/
apple/
apple_resized.png
apple_greyscale.png
apple_ascii.txt
banana/
banana_resized.png
banana_greyscale.png
banana_ascii.txt
For subsequent uses the first step can be skipped, so long as the intput/
directory exists.
Once the project is built, navigate to image-to-ascii/build/tests/
, and locate the testing executable.
The tests/../input/
directory should be populated by a sample image - if this isn't the case, then delete the image-to-ascii/build/
directory and rebuild the project.
Run the test(s) with the following command:
./image-to-ascii-tests
MSVC defaults to its implementation of secure _s
functions (that are poorly supported).
stb_image_write.h
(as of this commit ) defines __STDC_LIB_EXT1__
to determine whether or not to use these _s
functions, though certain versions of Visual Studio require __STDC_WANT_SECURE_LIB__
to function.
This project's workaround is defining _CRT_SECURE_NO_WARNINGS
in image.cpp
, to suppress deprecation warnings, in favour of the non _s
functions.
This project was built with Visual Studio, and has both Warnings as Errors (/WX
) and Warning Level Four (/W4
) enabled. This project also makes use of the stb image processing header libraries, which don't compile cleanly with /W4
.
This project's solution is wrapping the offending third party header library includes in #pragma warning(push, n)
and #pragma warning(pop)
to temporarily disable warnings:
#pragma warning(push, 0)
#include "stb_image.h"
#include "stb_image_write.h"
#include "stb_image_resize2.h"
#pragma warning(pop)
This is of course implementation defined, so not all compilers will support this. If this doesn't work for your specific compiler, consider temporarily disabling your equivalent of /W4
when using this project.