Discussion:
get image resolution
(too old to reply)
braedsjaa
2008-02-29 18:44:16 UTC
Permalink
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?
Norbert Hahn
2008-02-29 23:05:34 UTC
Permalink
Post by braedsjaa
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.
You may have a look at section "JFIF Segment Format" in
http://en.wikipedia.org/wiki/JPEG_File_Interchange_Format

HTH
Norbert
braedsjaa
2008-03-02 17:14:48 UTC
Permalink
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
follows:
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)

Loading...