You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3.0 KiB

DIP - Data In Picture

A tool to hide binary stuff into PNG pictures using LSB


This tool allow to hide any type of file in a PNG pictures, provided that the following conditions are respected :

  • the picture is a 8-bits depth RGB PNG
  • the data is small enough to fit in the picture (maximum ~21 bits/pixel)

The data will be hidden in the bits having the least importance in the picture in order to make the modification as imperceptible as possible.



A header is embedded in the picture alongside the data. He is split in two main parts :

  • LSB header (3 bits) : hidden in the 3 last bits of the R component of the first pixel, it contains the number of bits from the right reserved for the data in all the following components/pixels (Least Significant Bits). Its value is greater than 0 and lower than 8.

  • Main header (40 bits) :

    • Size header (32 bits) : stored like regular data accordingly to the lsb value found in the first header. Contains the size of the hidden data in bytes.
    • Reserved space (8 bits) : useless for now. Maybe forever. Consider it a wasted byte.

Reading this header needs to be done in two steps, as the first part is needed to retrieve the second one.

Storage capacity

For a picture of width x and height y, the maximum payload which can be hidden is given (in bits) by the formula

21 * x * y - 47

This capacity is only reachable by pretty much destroying the original picture, only leaving it one out of 8 bits in each channel (the LSB value as described in the header section will be 7). If you're not into deepfry aesthetics, you will want to keep this value below 5. For a target maximum LSB of 4, the formula is

12 * x * y - 44

Or, for a maximum LSB of v :

(x * y * 3 - 1) * v - 40

Please note that theses formulas describes the way the program is supposed to act, but my incompetence and a certain lack of tests may lead its real behavior to slightly differ from this values.



./dip -h <picture.png> <data> <output.png>

Hides data in picture.png and saves the resulting picture in output.png.


./dip -e <picture.png> <>

Extracts data hidden in picture.png and saves it in Using it on a picture which wasn't generated by DIP or has been altered is undefined behavior.


./dip -c <picture.png> <output.png>

Strips hidden data from picture.png and saves the resulting picture in output.png. Using it on a picture which wasn't generated by DIP or has been altered is undefined behavior.

Return Codes

  • 0 : everything's fine
  • 1 : small issue, like incorrect input
  • 2 : the data doesn't fit in the picture
  • 3 : a system call failed
  • 4 : PNG loading/saving-related error

External libs

PNG manipulation : LodePNG by Lode Vandevenne (zlib licensed).