A simple Zig program to convert PPM images to ASCII art. It supports multiple output modes, scaling, and optional saving of the output image.
To build the project:
zig buildThis will produce the executable at zig-out/bin/ppm_to_ascii.exe.
zig-out/bin/ppm_to_ascii.exe <image.ppm> [print_type] [scale] [--save]-
image.ppm
The path to the PPM image file you want to convert. -
print_type(optional)
Determines the ASCII output style. Options:normal→ standard grayscale ASCIIcolor→ colored ASCII using ANSI escape codesfull_color→ retains full RGB coloring in ASCII Default:normal
-
scale(optional)
A positive float that scales the image.- Values < 1 → downscale
- Values > 1 → upscale
Default:
1.0
-
--save(optional)
Saves the converted ASCII output tooutput.ppm. Without this flag, it only prints to the terminal.
- Convert
image.ppmto normal ASCII and print to terminal:
zig-out/bin/ppm_to_ascii.exe image.ppm- Convert
image.ppmto colored ASCII and save the output:
zig-out/bin/ppm_to_ascii.exe image.ppm color 1.0 --save- Convert
image.ppmto full-color ASCII, upscale by 2x, and save:
zig-out/bin/ppm_to_ascii.exe image.ppm full_color 2.0 --save- Scaling affects both terminal output and saved PPM file.
- Colors in
colorandfull_colormodes require a terminal that supports ANSI colors. - The program only supports PPM input.
- ASCII mapping uses an 8x16 font internally. Modify the font array for different ASCII styles.
This project is fully open source under the MIT License.