Announcement

Collapse
No announcement yet.

Where is dpi/density stored in the PNG file (how to get it using a hex editor)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Where is dpi/density stored in the PNG file (how to get it using a hex editor)

    Hi everyone

    Sort of a technical quesetion. Since it is possible to "embed" a dpi / density setting in a PNG file, it must reside somewhere in the PNG file header. For .jpg it is pretty easy to extract from the header (http://apptools.com/examples/dpi.php).

    Does anyone know where it is stored in an PNG file?

    Best regards
    Wuhtzu, Denmark

    #2
    It turns out that it was a question of reading the PNG specification: http://www.libpng.org/pub/png/book/title.html. More precisely http://www.libpng.org/pub/png/spec/1...ks.html#C.pHYs

    So looking at a png in my hex editor i found:

    70 48 59 73 00 00 0E C3 00 00 0E C3 01

    The first 4 bytes (70 48 59 73) corresponds to pHYs (http://en.wikipedia.org/wiki/ASCII) which is the start of the dpi/density/physical dimension chunk in the png.

    The next 2x 4 bytes (00 00 0E C3 00 00 0E C3) correspond to 3779 in decimal which is 96 DPI in units of dots per meter (96 dots per inch / 0.0254 meter per inch = 3779 dot per meter). And the last 01 corresponds to the units being "dots per meter" as specified in the png specification.

    Now only one question remains. Why doesn't IrfanView detect the new DPI if I change the numbers in my hex editor (UltraEdit)

    Comment


      #3
      Originally posted by wuhtzu View Post
      Now only one question remains. Why doesn't IrfanView detect the new DPI if I change the numbers in my hex editor (UltraEdit)
      can you post the two png files (original + your hex-edited one). I can look at it, maybe I find problem?
      Until IrfanView grants the user access to PNG metadata (see http://en.irfanview-forum.de/vb/show...tadata-support ) you are stuck with hex-editing or other programs. However if the DPI value is your only such problem, that's one thing you CAN do in IrfanView. I just tested it. In IV I opened a png image set to 72 dpi, pressed the i key and IV showed the info-box with 72 dpi. I entered 96 dpi, clicked on the "change" button and saved the file, closed and re-opened it, and it's still 96 dpi, so it works. I also checked and the info is indeed written where it belongs, i.e. the pHYs chunk.

      Problem solved?

      Comment


        #4
        PS: Pay attention though, because saving to PNG with IrfanView can entail other problems, notably the following (I don't know if any or all of these have been solved in the meanwhile. Just to make sure you don't lose any data through IV operations.)

        Originally posted by PhiLho View Post
        Currently, if I open a PNG file with IV then save it under another name, I loose the tEXt chunks, but also the gAMA one, the bKGD one (background color), the tIME and even worse, IV converts it from grayscale+alpha to simple paletted image. If I ask to save with transparent color, IV asks me the unique transparent color instead of preserving the previous alpha info...
        Originally posted by j7n View Post
        These are indeed valid requests. I think at the moment IrfanView does not know the meaning of grayscale. Upon opening a grayscale PNG it interprets it as 8-bit image with a known palette.

        Comment

        Working...
        X