Search This Blog

Saturday, February 2, 2019

Merging Images into a PNG that Displays Different Sub-Images Among Different Renderers

I recently wrote a cool program called JanusPNG.  It basically merges two PNGs that look completely different into one image.  Then, with a cool little gamma value trick for PNGs, the final image would display different images depending on how the renderer reads the PNG specifications.  Make sure to check out the program here.  It leads to some interesting results and can have great prank/shock value for forum posts, emails, and text messages.  The PNGs will always look different from its thumbnail because of the gamma trick.  There are also several other features in this program detailed on the repo.

 Before I explain any further, thanks to for providing all the knowledge necessary for me to write my version of this trick.

Here are some examples created with JanusPNG (Note that since Blogger messes up the PNG data, I just attached screenshots from different renderers.  The actual examples are on the Github repo mentioned above):
Example 1:

First image (yes, I know about the annoying background transparency pixels, but it was just a screenshot)

Second Image
Thumbnail Display

Fully Rendered Display
Example 2:

First Image

Second Image

Thumbnail Display

Fully Rendered Display
Example 3:

First Image

Second Image
Thumbnail Display

Fully Rendered Display

How does it work in detail?
* Exploits the gAMA chunk in PNG files.  Some renderers that follow the specs exactly utilize this formula: output = image^(1 / gamma).  So if the gamma value is very low, the darks become very dark and the lights will look normal.
* We first must fade the image (one darkened, the other lightened) before adding the gAMA chunk
* We also must combine the "faded" pixels of both images before merging into one "JanusPNG"
I used the Python Pillow library to help me write this program.

Usage Information:
-1, --image1: first image (the one that is usually hidden unless opened in a proper renderer)
-2, --image2: second image (the one that usually appears as the thumbnail)
-o, --output: output file name
-v, --version: shows version
-s, --silent: silent mode (no output on the terminal)
-h, --help: shows this information
Threading used to exist, but too many issues existed.  Other implementations were actually slower too.  If you have a good and fast implementation, please let me know.

Note that the entire project is licensed under the GNU GPL v2.  There is also a GUI and autofilling capabilities (images of different sizes can be merged).  In the meantime, go play around with it and send some JanusPNGs (or Magic PNGs) to your friends!

No comments:

Post a Comment