https://github.com/timhanewich/photoencoding
Encode any file into a bitmap image representation
https://github.com/timhanewich/photoencoding
binary bitmap decryption encryption imgur
Last synced: 2 months ago
JSON representation
Encode any file into a bitmap image representation
- Host: GitHub
- URL: https://github.com/timhanewich/photoencoding
- Owner: TimHanewich
- License: mit
- Created: 2024-01-14T13:27:20.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2026-04-11T19:35:24.000Z (2 months ago)
- Last Synced: 2026-04-11T21:20:53.542Z (2 months ago)
- Topics: binary, bitmap, decryption, encryption, imgur
- Language: C#
- Homepage:
- Size: 15.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
README
# File to Photo Encoding
This C# (.NET) project is capable of encoding any file's binary content into a bitmap image, and then decoding the encoded image back to the original file:

Both the original file name (including extension) and the binary content of the original file is encoded into the RGB values of the pixels of the resulting encoded file.
As an example, the below image is the fully encoded [**December 2023 Microsoft Power Platform Licensing Guide**](https://go.microsoft.com/fwlink/?linkid=2085130), ~965 KB.

## Why did I make this?
Image hosting services like [Imgur](https://imgur.com/) allow users, both authenticated and anonymous, to store full uncompressed bitmap images for free. By converting files to bitmap images using this program, we essentially gain the ability to now store any *file* on Imgur as well:
1. Convert a file to an encoded image.
2. Upload the encoded image to Imgur.
3. Download the image from Imgur.
4. Use this program to decode the image back to the original file state.
> **⚠️ Important:** If you plan to host encoded images on [Imgur](https://imgur.com/), be aware that Imgur compresses images over **1 MB** for anonymous uploads and over **5 MB** for account holders. Compression will result in loss of encoded data, making the image undecodable. Ensure your encoded images stay under these limits.
The steps above fully describe the process of both uploading and retrieving a file content from any image hosting site, but Imgur being used specifically here.
This project is experimental in nature - the steps above can, obviously, be cumbersome for a large number of files. Perhaps some of those steps can be programmatically automated as well. This project was an experiment to see if this idea of mine could be accomplished, which it has proven to be.
## How to Use - CLI
The program runs as a command-line tool with two commands:
### Encoding
Encode any file into a bitmap image (PNG and JPG are tested and proven to work well):
```
PhotoEncoding encode
```
Example:
```
PhotoEncoding encode "History of Space Exploration.docx" encoded.png
```
The resulting `encoded.png` file will look something like this:

The encoded image contains both the encoded name of the original file (including its extension) and the file's binary content itself.
### Decoding
Decode an encoded image back into its original file. The decoded file is written to the current directory with its original file name:
```
PhotoEncoding decode
```
Example:
```
PhotoEncoding decode encoded.png
```
## Code Examples
You can also use the `PhotoEncoder` and `PhotoDecoder` classes directly in your own code.
### Encoding
```csharp
PhotoEncoder pe = new PhotoEncoder(@"C:\Users\timh\Downloads\History of Space Exploration.docx");
pe.Encode(@"C:\Users\timh\Downloads\encoded.png");
```
### Decoding
```csharp
string EncodedFilePath = @"C:\Users\timh\Downloads\encoded.png";
string OutputFolderPath = @"C:\Users\timh\Downloads\DECODE HERE";
PhotoDecoder pd = new PhotoDecoder(System.IO.File.OpenRead(EncodedFilePath));
Console.WriteLine(pd.DecodeFileName()); // "History of Space Exploration.docx"
string OutputFilePath = Path.Combine(OutputFolderPath, pd.DecodeFileName());
Stream OutputTo = System.IO.File.OpenWrite(OutputFilePath);
pd.Decode(OutputTo);
OutputTo.Close();
```
The `PhotoDecoder` class has a function for finding, extracting, and decoding the original file name and extension. You can use this to determine the file's original name and then decode the image into a file with the same name, as shown above. Or, at the very least, you can use this to read the extension of the file, thus understanding what file type this is and how to open it.
## Limitations
Because this C# program uses the [System.Drawing.Common](https://www.nuget.org/packages/System.Drawing.Common) Nuget package and this Nuget package is only supported on Windows machines, this program will **only** run on Windows devices.