A Python application that encodes binary data from any file into an image and decodes it back to its original form. The encoding process converts file bytes into RGB pixel values, while the decoding process extracts the original data from the image pixels.
- Universal File Support: Encode any type of file (text, binary, images, documents, etc.) into an image
- Lossless Encoding: Perfect reconstruction of original files with no data loss
- Smart Decoding: Automatic detection of encoded data boundaries
- Flexible Image Dimensions: Auto-calculation of optimal image size or manual specification
- Command-Line Interface: Easy-to-use CLI with comprehensive options
- Error Handling: Robust error checking and informative error messages
- Cross-Platform: Works on Windows, macOS, and Linux
- Python 3.8 or higher
- Pillow (Python Imaging Library)
-
Clone the repository:
git clone https://github.com/Fr3d33/file-to-image.git cd file-to-image -
Install dependencies:
pip install -r requirements.txt
Or install Pillow directly:
pip install Pillow
Encode a file to image:
python Encode.py input.txt output.pngDecode image back to file:
python Decode.py encoded.png decoded.txtEncode with specific dimensions:
python Encode.py data.bin image.png --width 800 --height 600Decode with smart detection:
python Decode.py image.png output.bin --method smartUse default sample files:
python Encode.py # Uses Sample/Encode.txt β Sample/Encode.png
python Decode.py # Uses Sample/Encode.png β Sample/Decode.txtinput_file: Path to the file to encode (default: Sample/Encode.txt)output_image: Path for the output image (default: Sample/Encode.png)--width WIDTH: Specify image width (auto-calculated if not provided)--height HEIGHT: Specify image height (auto-calculated if not provided)--version: Show version information
input_image: Path to the image to decode (default: Sample/Encode.png)output_file: Path for the output file (default: Sample/Decode.txt)--method METHOD: Decoding method ('count' or 'smart', default: 'smart')--version: Show version information
- smart: Finds the last non-white pixel for accurate data boundary detection (recommended)
- count: Counts all non-white pixels (legacy method, may include extra padding)
file-to-image/
βββ Encode.py # Main encoding script
βββ Decode.py # Main decoding script
βββ requirements.txt # Python dependencies
βββ README.md # Project documentation
βββ LICENSE # License file
βββ .gitignore # Git ignore rules
βββ tests/ # Unit tests
β βββ test_encode.py
β βββ test_decode.py
β βββ test_data/
βββ Sample/ # Sample files for testing
βββ Encode.txt # Sample input file
βββ Encode.png # Encoded image output
βββ Decode.txt # Decoded output file
- File Reading: Read the input file as binary data
- Padding: Add null bytes if needed to make the data length divisible by 3
- RGB Conversion: Group bytes into sets of 3, treating each set as RGB values (0-255)
- Image Creation: Create an image with white background and set pixels to the RGB values
- Dimension Calculation: Auto-calculate optimal dimensions or use provided values
- Image Saving: Save the resulting image in PNG format
- Image Loading: Open and validate the encoded image
- Data Detection: Find pixels containing encoded data (non-white pixels)
- RGB Extraction: Extract RGB values from each data pixel
- Byte Reconstruction: Convert RGB values back to individual bytes
- Padding Removal: Remove null byte padding added during encoding
- File Writing: Write the reconstructed bytes to the output file
The project includes comprehensive tests to ensure reliability:
# Run all tests
python -m pytest tests/ -v
# Run specific test files
python -m pytest tests/test_encode.py -v
python -m pytest tests/test_decode.py -v
# Test with the included sample
python Encode.py Sample/Encode.txt Sample/Test.png
python Decode.py Sample/Test.png Sample/Test.txt
# Compare Sample/Encode.txt and Sample/Test.txt - they should be identical- Image Capacity: Each pixel can store 3 bytes of data
- Maximum File Size: Limited by maximum image dimensions (e.g., 10,000 x 10,000 = 300MB capacity)
- Supported Formats: Output images are saved as PNG to preserve exact pixel values
- File Types: Any file type can be encoded (binary data is treated universally)
- Data Hiding: Embed data in images for steganography-like applications
- File Backup: Convert files to image format for unique storage solutions
- Data Transmission: Send files through image-sharing platforms
- Educational: Demonstrate concepts of data encoding and binary representation
- Art Projects: Create visual representations of data/files
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
This tool is for educational and legitimate purposes only. Users are responsible for complying with applicable laws and regulations when using this software.
- Very large files may require substantial memory during processing
- Image viewers might compress or modify pixel values - always use the original PNG files for decoding
If you encounter any issues or have questions:
-
- Check the Issues page for existing solutions
- Create a new issue if your problem hasn't been addressed
- Provide detailed information including error messages and steps to reproduce
- Support for different image formats (TIFF, BMP)
- Compression options to reduce image file size
- GUI interface for non-technical users
- Batch processing capabilities
- Progress bars for large files
- Encryption options for secure data hiding
- Metadata preservation
Made with β€οΈ for the open source community