https://github.com/ccianos/byterep
Encode and decode jpg images and display them using Unicode representation.
https://github.com/ccianos/byterep
cli command-line decoding encoding go golang-examples images jpg representation unicode unicode-characters
Last synced: 18 days ago
JSON representation
Encode and decode jpg images and display them using Unicode representation.
- Host: GitHub
- URL: https://github.com/ccianos/byterep
- Owner: ccianos
- License: mit
- Created: 2024-04-03T10:55:47.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-11-03T10:17:43.000Z (8 months ago)
- Last Synced: 2025-11-23T11:08:29.220Z (7 months ago)
- Topics: cli, command-line, decoding, encoding, go, golang-examples, images, jpg, representation, unicode, unicode-characters
- Language: Go
- Homepage:
- Size: 10.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# ByteRep
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.
## Installation
Clone the repository and build the executable:
```bash
git clone https://github.com/ccianos/byterep.git
cd byterep
go build -o byterep
```
## Usage
### Encode an Image
Encode an image to bytes. The original format (JPEG or PNG) is preserved in the byte output.
```bash
# Encode a JPEG
./byterep -encode -input input_image.jpg > encoded_image.txt
# Encode a PNG
./byterep -encode -input input_image.png > encoded_image.txt
```
### Decode an Image (Smart Output)
The `-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.
1. Display as Unicode (in Terminal)
When you run `-decode` and the output is your terminal, it will display the image using Unicode characters.
```bash
# 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
```
2. 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.
```bash
# 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
```
3. Force Display of Unicode Text (Redirected Output)
```bash
# 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
```
## Options
- `-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
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE.md) file for details.