ASCII Image Converter
This is a small command-line tool to convert an image to ASCII art. It takes an image file as input and generates ASCII art on the console.
Usage
go run main.go [image_file_path]
Replace [image_file_path]
with the path to the image file you want to convert.
Requirements
How it works
- The tool loads the specified image file using the
loadImage
function. It supports PNG and JPEG image formats.
- It iterates over each pixel in the image and converts it to grayscale.
- The grayscale value is used to determine the density value, which represents the ASCII character to be used.
- The tool prints the ASCII character corresponding to the density value to the console.
- The process is repeated for each pixel in the image until the entire image is converted to ASCII art.
ASCII Density Chart
The following density chart is used to convert grayscale values to ASCII characters:
" "
- Lowest density (grayscale value 0)
"."
- Low density
"="
- Medium density
"!"
- High density
"░"
- Higher density
"▒"
- Even higher density
"▓"
- Very high density
"█"
- Highest density (grayscale value 255)
Example
go run main.go example.png
Output:
█████████████████████████████████████████████████
█████████████████████████████████████▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓▓
██████████████████████████████▓▓▒▒▒▒▒▒▒▒░░░░░░░░░░░░░▒▒
███████████████████████████▒▒▒▒▒▒░░░░░░░░░░░░░░░░░░░░░░
████████████████████████▒▒▒▒░░░░░░░ ░░░░░░░░░░
████████████████████▒▒▒▒░░░░░░░░░░░ ░░░░░░░░░░░░░░
...
License
This project is licensed under the MIT License.
© Copyright [2023] NotYourAnonOne