Page 1 of 1

Check image dpi resolution

Posted: Wed Jan 26, 2005 1:21 pm
by elibarnett
I need to check an uploaded image resolution in dpi, how can I do this in php?

Posted: Wed Jan 26, 2005 1:32 pm
by feyd
any particular image formats?

basically jpg, maybe gif and png

Posted: Wed Jan 26, 2005 1:49 pm
by elibarnett
basically jpg, maybe gif and png

Posted: Wed Jan 26, 2005 2:00 pm
by feyd
as far as I know, php does not have functions to find that information. ImageMagick may, along with other graphics tools.

Re: basically jpg, maybe gif and png

Posted: Wed Jan 26, 2005 5:13 pm
by onion2k
elibarnett wrote:basically jpg, maybe gif and png
According to a quick test I just did using photoshop none of those image formats retain the dpi resolution when saved. I created a file 800*800 pixels square, and 350 DPI. I then saved it in gif, jpg, and png formats. When I opened each of the saved files they all defaulted to 72 dpi..

So it would appear to be impossible.

Posted: Wed Jan 26, 2005 9:57 pm
by JAM
As onion2k mention...

Almost certain that those imagetypes are compressed, hence the dpi will wash away. Only TIFF and perhaps BMP and a common Mac format (PICT ? Not sure.) save that info I belive.

Reserve myself for ev. errors though.

Posted: Wed Jan 26, 2005 10:03 pm
by feyd
png has an optional data chunk for pixels per unit marking.

the others do not, that I'm aware of.

Posted: Thu Jan 27, 2005 3:13 am
by JayBird
Of course all the above image types have a DPI (PPI)....Dots Per Inch/Pixels Per Inch.

You will not be able to get the DPI of an image becuase the figure doesn't really exist. Well, it does, but it is determined by other factors. Lets look at an example.

You take a photo with your digital camera at 2200px X 1700px and this has a resolution of 72dpi.

This would mean the print size of the image is 30" x 23". (2200/72 and 1700/72)

Now, you need to use this image in a magazine and the publisher requires that you provide a 300 DPI image. Not a problem.

Take our original image.

Lets work out the maximum size we can print this image in the magazine.

2200/300 = 7.3
1700/300 = 5.6

which would mean the maximum size you could print this at 300dpi would be 7.2" x 5.6".

Anyway, i have probably gone into too much detail about DPI....but it just illustrates you can work out the DPI using other methods cos DPI isnt really set.

You could work it out from the pixel dimensions and the print size, but i am not sure if PHP can get this information for you.

Mark

Posted: Thu Jan 27, 2005 4:04 am
by onion2k
The thing it though, if I make a PSD file and set it to 300 DPI, and send it to you, you'll be able to print it and view it exactly as I intended. If I save the same file as a JPG and send it to you then you'll only be able to guess how big I intended it to be.

I assume thats what elibarnett needs to know.. Personally I'd just have a DPI text input box alongside the image upload element.. That'd solve the problem quite nicely.

Posted: Thu Jan 27, 2005 4:39 am
by JayBird
onion2k wrote:The thing it though, if I make a PSD file and set it to 300 DPI, and send it to you, you'll be able to print it and view it exactly as I intended. If I save the same file as a JPG and send it to you then you'll only be able to guess how big I intended it to be.
Not true.

Just tested it right now. Create a new file in PS at 300dpi. Save a JPG, re-open, file is still 300dpi

Posted: Thu Jan 27, 2005 5:26 am
by onion2k
Bech100 wrote:Just tested it right now. Create a new file in PS at 300dpi. Save a JPG, re-open, file is still 300dpi
I tried that last night and it defaulted back to 72. Maybe it depends on your settings. I certainly wouldn't trust every JPG someone uploads to have that sort of information included.

Posted: Thu Jan 27, 2005 5:36 am
by AGISB
Somehow the dpi is saved in the jpg but the file is exactly the same size on disk if it is 180 dpi or 96.
Have never noticed that before.

Posted: Thu Jan 27, 2005 5:39 am
by JayBird
I ve worked in the Design & Advertising industry for many years now and never come across a situation where DPI has change withouy specifically telling it to.

On another note, i like what you are doing with your PHPhoto project, very impressive.

Posted: Thu Jan 27, 2005 5:43 am
by JayBird
AGISB wrote:Somehow the dpi is saved in the jpg but the file is exactly the same size on disk if it is 180 dpi or 96.
Have never noticed that before.
Yeah, it would.

The pixel dimension are exacltly the same no matter what the DPI is (unless you resample).

A 144 x 144 pixel image @ 72dpi = 2" x 2" when printed

A 144 x 144 pixel image @ 144dpi = 1" x 1" when printed


Each image is still the same file size

Working out image files sizes from dimensions

No of pixels in length x No of pixels in height = total No of pixels

Total No of pixels x "No of bits per colour" / 8 = total No of bytes

So for example:

2867 (width in pixels) x 2034 (height in pixels) = 583,1478 pixels

583,1478 x (24/8) = 17,494,434 bytes or 17.5 Mb

Posted: Thu Jan 27, 2005 8:30 am
by feyd
the thing I was saying is there is not native tag for physical dimensions in the JPEG or GIF standards. i.e. It's quite possibly a Photoshop comment/extension.. sadly my Photoshop doesn't want to start today.. I'll do some checking when I get it back up.

edit: okay.. I had another look at the JFIF headers, and I missed it earlier.. the pixel density information is stored at 0Ah and 0Ch in 2 byte chunks each for horizontal and vertical density respectively.