I started learning golang last week (February 2024), and this is my first project using it.
the program takes a PNG image and converts it to ascii art.
First I split the image into pixels, each pixel has an RGB value. I use the RGB value to determine the brightness of a each pixel. finally I map the brightness to a character from an ascii character set and output the result to a file
Here is what the output looks like (this is k9 from doctor who!)
![](https://private-user-images.githubusercontent.com/77839865/309559230-4fc4223c-2ed8-4cee-b03a-659b452775a1.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU5NzE1MDEsIm5iZiI6MTcyNTk3MTIwMSwicGF0aCI6Ii83NzgzOTg2NS8zMDk1NTkyMzAtNGZjNDIyM2MtMmVkOC00Y2VlLWIwM2EtNjU5YjQ1Mjc3NWExLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MTAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTEwVDEyMjY0MVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTcyY2EzOWE3OTQzNDY0NjM3N2Y2ODExNjQyYTM5NTk5MWIxOTJjMGQxYjIxYWQ4M2I4MjZiYTlkODI3MTc1YTQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.BClh2QhOlNfGbKTZJVn_4QUJZxe7rejxhmpSNvT79Wk)
- Install golang
- clone the project
git clone https://github.com/spcbfr/ascii-go.git
- run
go build .
- run
./ascii-go
(ascii-go.exe
if you're on windows) you should see the usage instructions
The result is best viewed with a zoomed-out text editor with no-syntax highlighting, a low line-height improves the effect further too.
Note: if the output doesn't look totally right, try using the --invert
flag. this uses denser characters for lower brightness pixels and vice-versa
Happy Ascii-ing!
- support Image formats other than PNG
- better brightness calculation algorithm
- pull image from remote source
- reduce image size for images larger than a certain size