get image resolution

get image resolution

Post by braedsja » Sun, 02 Mar 2008 03:44:16

I am writing a database application which needs to export documents in
RTF format. So far text export is working well but now we need to
include jpeg images. The rtf format uses dpi resolution as well as
pixel dimensions to work out image size on page which means that
before I can include the actual jpeg data in the exported file I need
to find out this metadata from which to calculate resizing ratios in
order to display reasonably.

I was hoping to use perl or PHP but for all my searching I only find
numerous ways to get the size in pixels but can't figure out how to
get the resolution information I need.
(if it is in EXIF that can't be relied upon to always be present)

Any ideas?


get image resolution

Post by Norbert Ha » Sun, 02 Mar 2008 08:05:34

You may have a look at section "JFIF Segment Format" in



get image resolution

Post by braedsja » Tue, 04 Mar 2008 02:14:48

Thanks, that did get me there in the end :-)

For anyone else trying to figure this out ...

When you have converted a binary jpeg file into a hex string, the
resolution info should be encoded in a JFIF header and can be found as
look for 5 bytes 4A46494600 (this translates as ascii JFIF0)
this is followed 2 bytes of version number (usually 0101)
then 1 byte indicating inches or cm (01 or 02)
then 2 bytes for horizontal pixel density (dots per inch/cm)
then 2 bytes for vertical pixel density (dots per inch/cm)