Page 1 of 1
how do you read an image's resolution ?
Posted: Tue Aug 12, 2008 1:11 am
by scheinarts
Hi guys,
Im wondering how would it be possible to read an image's resolution. I checked out the documentation on the GD lib and there seems to be no method specific to this. There is the getimagesize() method, but im not sure this will allow you to read the images dpi.
Im positive this is possible to do with jps and tiffs I imagine, I just need a little pointer how to achieve this.
Going off on a tangent here, would it possible to read data from an image in .RAW format, and use the GD lib to create a jpeg from that to display on the browser. I highly doubt this is possible but I just thought I'd ask in case.
Many thanks, hopefully I can he some pointers on how to read the images dpi.
Re: how do you read an image's resolution ?
Posted: Tue Aug 12, 2008 2:30 am
by onion2k
JPG images don't store the print resolution anywhere inside them so you can't read it. I'm not sure about TIFFs.
Reading .RAW images isn't possible either. You could always write something to load them, but RAW isn't a proper agreed format so you'll have to write a parser for the Canon, Nikon, Minolta, Olympus etc versions of the format. Plus RAW images are huge - do you really think people are going to want to upload files that big? And even if they did you'd hit PHP's memory limit pretty quickly.
Re: how do you read an image's resolution ?
Posted: Tue Aug 12, 2008 4:20 am
by scheinarts
hi there,
thanks for the response.
searching around i found out that in the EXIF data the image res is in fact saved, and you can extract that just using the exif_read_data() method.
Here is my finding
http://www.alperguc.com/blog/php_progra ... exif-data/
So how come you say its impossible to read the res from a jpg?
Re: how do you read an image's resolution ?
Posted: Tue Aug 12, 2008 4:44 am
by onion2k
EXIF is optional metadata information. You can't rely on it being there because it really depends on the jpeg library that whatever created the jpeg used. If your source images are always coming from the same place and they'll always have it, then it's a decent solution though.
Re: how do you read an image's resolution ?
Posted: Tue Aug 12, 2008 5:10 am
by scheinarts
So how do large image banks that sell stock photography manage this. They always display the images res along with the size purchase options. Basically 300 or 72 is the norm.
iStockphoto for example, which is built on php does this. How do they manage to display the images resolution always (72 and 300 is what i always see)? Im sure they cant rely on their content authors always uploading images with exif data, so how do they get the res at which the image was uploaded in.
This is just to determine which images are good for print, and which are just for web.
This brings to to a second point, which im pretty sure you know the answer... How do you downsize a 300 dpi image to 72dpi. I'm already familiar with making smaller versions from larger ones using the gd lib, but im not sure how the resolution is managed in this case. Can you shed some light on this topic please.
Thank you very much onion2k for all the responses. I really appreciate it.
Re: how do you read an image's resolution ?
Posted: Tue Aug 12, 2008 5:18 am
by scheinarts
by the way, your PHP Image looks very interesting and very easy to use. I will give this a try on the project im working on and definitely give some feedback.
Re: how do you read an image's resolution ?
Posted: Tue Aug 12, 2008 7:02 am
by onion2k
scheinarts wrote:So how do large image banks that sell stock photography manage this. They always display the images res along with the size purchase options. Basically 300 or 72 is the norm.
iStockphoto for example, which is built on php does this. How do they manage to display the images resolution always (72 and 300 is what i always see)? Im sure they cant rely on their content authors always uploading images with exif data, so how do they get the res at which the image was uploaded in.
I imagine they use the EXIF data if it's there, and just make a judgement call based on pixel resolution if it's not. Say, more than 2000 pixels = print quality, less than 2000 = screen quality.
This is just to determine which images are good for print, and which are just for web.
This brings to to a second point, which im pretty sure you know the answer... How do you downsize a 300 dpi image to 72dpi. I'm already familiar with making smaller versions from larger ones using the gd lib, but im not sure how the resolution is managed in this case. Can you shed some light on this topic please.
There's no difference in the actual bitmap data between a 72DPI image and a 300DPI image. It's just a value that's used to calculate the width and height that the image should be printed at. If you want to display a 300DPI image on screen
at the same size it would print at then you need to reduce to 24% of it's current (pixel) resolution ((72/300)*100=24). The problem with that though is that monitors aren't 72DPI. The actual dot pitch (size of the pixels) depends on the monitor, the screen size and screen resolution it's set to.
Re: how do you read an image's resolution ?
Posted: Tue Aug 12, 2008 2:05 pm
by scheinarts
I see what you mean. Thanks for the clarifications.
Is there any special way or technique that say iStockphoto manages to reduce images size to sell them at a lower price/size ? Or any special logic thats a little more advanced that just resizing down an image. What about keeping quality intact when sizing down say from an image thats 3000 down to a 640 width. I imagine someone has already figured out this workflow. Would you have any code examples or some sort of logic to follow. Many thanks again.