That's an interesting question. I have to admit that I've wondered
the same thing in the past, when placing EPS files into other
documents. I don't think that the information you're seeking is
available easily online, but I do have a possible solution for you.
As you're probably aware, the EPS file format can contain both raster
(bitmapped) and vector graphic information. Frequently EPS files are
used for scalable clipart in production. Similarly, there are a
variety of acceptable data formats for EPS files, including ASCII or
Binary encoding, with and without embedded previews, and including
previews in various color depths.
I note from the file header you provided that you're using Photoshop
5, generating an EPS file compliant with version 3 of the EPS
specification. If you're curious about the details, you can find a
copy of the EPS 3.0 Specification document mirrored in various
locations on the net, including here:
The key here though, is that the EPS header does not contain the DPI
information for the raster graphic, just the bounding box for the
default resolution. The actual DPI information is stored with the
image data in the (undocumented?) Photoshop data.
This data is the Photoshop-specific information that is entered into
the file, starting with the %BeginPhotoshop header. I did a simple
test, generating two identical blank eps files from Photoshop, at
different resolutions and then compared the files for differences
using the free utility WinMerge ( http://winmerge.sourceforge.net/ )
The first line after the %BeginPhotoshop varies slightly!
(image at 72 dpi)
(image at 600 dpi)
So what are these numbers? Well, 72 in Hexadecimal is 48, and 600 in
hexadecimal is 258. Bingo!
So the simplest answer to your question is probably, read the last 4
characters of the line immediately after %BeginPhotoshop, and convert
from Hexadecimal. Naturally this solution is particular to
Photoshop-generated EPS files. And of course, if the EPS has been
saved in Binary encoding instead of ASCII, text processing of the file
is unlikely to be feasible.
I hope this answers your question satisfactorily. If you need
additional information about what I've discussed, please don't
hesitate to post a request for clarification prior to rating.
Clarification of Answer by
22 Oct 2002 13:55 PDT
Ok, after looking at this further I think Im closer. First, I did my
test in Photoshop 6. My test images worked fine, but subsequently
I've managed to generate files that don't have the dpi info at the end
of the line (similar to the one from version 5 which you provided.)
This indicates that the header is of variable length, not static as I
had previously assumed. Oops. Sorry.
The good news however is that the contents of the %BeginPhotoshop
section are indeed hexadecimal, and the first few characters when
translated from Hex to ASCII read "8BIM", which is a standard header
indicator for Photoshop.
It's likely that this data is a Photoshop image resource block; see
page 7 of the PDF you referenced in your question.
The following page may also be of use, as it gives some details about
parsing 8BIM headers:
Clarification of Answer by
22 Oct 2002 15:32 PDT
Ok, this will probably be my last post on this question. I just
wanted to point out that since the opensource program GIMP (the Gnu
Image Manipulation Program) reads Photoshop documents, there is
already available source code that demonstrates parsing the Photoshop
image header. If you're curious you can download the source code from
various mirrors mentioned at www.gimp.org. In particular, from the
PSD.C file of the source code, I find:
IFDBG printf ("\t\tResolution Info:\n");
psd_image.resolution_is_set = 1;
psd_image.resolution.hRes = getglong(fd, "hRes");
psd_image.resolution.hRes_unit = getgshort(fd, "hRes_unit");
psd_image.resolution.widthUnit = getgshort(fd, "WidthUnit");
psd_image.resolution.vRes = getglong(fd, "vRes");
psd_image.resolution.vRes_unit = getgshort(fd, "vRes_unit");
psd_image.resolution.heightUnit = getgshort(fd, "HeightUnit");
(*offset) += Size;
IFDBG printf("\t\t\tres = %f, %f\n",
psd_image.resolution.hRes / 65536.0,
psd_image.resolution.vRes / 65536.0);
So it looks like there are 6 pieces of information in the
ResolutionInfo structure that follows the 0x03ED flag.
Notice how my first answer showed the DPI in two places? That because
one's the horizontal resolution and one's the vertical. (I'd imagine
for any Photoshop-generated bitmap that the DPI would be equal for
horizontal and vertical.)
With this information you may be able to write a program or script
that can properly parse the ResolutionInfo structure after you locate
it in the header.