This is a simple command-line tool for encoding and decoding JPEG and PNG images to and from bytes, with an option to display images on the command-line using Unicode characters.
Clone the repository and build the executable:
git clone https://github.com/ccianos/byterep.git
cd byterep
go build -o byterepEncode an image to bytes. The original format (JPEG or PNG) is preserved in the byte output.
# Encode a JPEG
./byterep -encode -input input_image.jpg > encoded_image.txt
# Encode a PNG
./byterep -encode -input input_image.png > encoded_image.txtThe -decode command is now TTY-aware. It changes behavior based on whether you're viewing it in a terminal or redirecting the output to a file.
- Display as Unicode (in Terminal)
When you run
-decodeand the output is your terminal, it will display the image using Unicode characters.
# Display an encoded file as Unicode
./byterep -decode -input encoded_image.txt
# You can also display an original image file directly as Unicode
./byterep -decode -input input_image.jpg
./byterep -decode -input input_image.png- Reconstruct Image File (Redirected Output)
When you redirect the output (using
>), the command writes the raw image bytes, reconstructing the original file.
Note: Ensure your output file extension (.jpg or .png) matches the format of the original image you encoded.
# Reconstruct a JPEG image
./byterep -decode -input encoded_image.txt > decoded_image.jpg
# Reconstruct a PNG image
./byterep -decode -input encoded_image.txt > decoded_image.png- Force Display of Unicode Text (Redirected Output)
# You can force Unicode text on redirected output
./byterep -decode -unicode -input input_image.jpg > unicode_output.txt
./byterep -decode -unicode -input input_image.png > unicode_output.txt
./byterep -decode -unicode -input encoded_image.txt > unicode_output.txt-encode: Encode the input JPEG or PNG image to bytes-decode: Decode the encoded data. Displays as Unicode to a terminal, or writes raw image bytes if redirected.-unicode: Force Unicode text output, even when redirecting.-input: Input file path-help: Show help message
This project is licensed under the MIT License - see the LICENSE file for details.