Overview
This project explores an unconventional approach to cloud storage: encoding text data as black-and-white pixel images and uploading them to image-hosting platforms. Each pixel in the output image represents a single bit — white (255) for 1, black (0) for 0 — making any text file visually reconstructable from a saved image.
How It Works
The pipeline has two core stages:
1. Text → Binary String
Every character in the input file is converted to its 8-bit ASCII binary representation using Python’s format(ord(char), '08b'). The resulting string is a flat sequence of 0s and 1s.
2. Binary String → Image
The binary string is reshaped into a 2D array of a user-defined width. Each 0 or 1 maps to a black or white pixel respectively. The image is written as a 3-channel (RGB) array using NumPy and saved via OpenCV.
Code Breakdown
| Component | Description |
|---|---|
text_to_binary(text) | Converts a string to a flat binary representation |
binary_to_image(binary_string, width) | Reshapes binary data into an OpenCV-compatible image array |
image_width | Controls the pixel width of the output (and therefore image height) |
cv2.imwrite() | Saves the final image as a .png file |
Dependencies
- OpenCV (
cv2) — image construction and I/O - NumPy — array manipulation and reshaping
Install with:
pip install opencv-python numpy
Usage
- Place your text content in
input.txt - Set your preferred
image_width(e.g.20pixels wide) - Run the script:
python encoder.py
The encoded image is saved as savedfile.png and displayed in a preview window.
Example
A plain text file containing Hello (5 characters × 8 bits = 40 bits) with image_width = 20 produces a 2 × 20 pixel image — each row representing 20 bits of the message.
Notes & Limitations
- Image width directly affects aspect ratio; wider images produce shorter, wider outputs.
- Padding with zero-bits is applied when the binary length isn’t a clean multiple of
image_width. - Platform compression (e.g. Instagram’s JPEG re-encoding) may corrupt pixel values — lossless formats and platforms are recommended for reliable decoding.
Potential Extensions
- Decoder — reconstruct the original text from a saved image
- Compression — apply run-length or Huffman encoding before conversion
- Error correction — embed redundancy bits to survive lossy re-encoding
- Colour channels — encode 2 or 3 bits per pixel using RGB values