Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get image resolution with PHP

Status
Not open for further replies.

Spork52

Programmer
Nov 20, 2007
134
US
Is there a way of retrieving image resolution with PHP?

getimagesize() only gets the pixel dimensions. I need the resolution or physical size so that I can scale uploaded images to 72 dpi on the assumption that they are 100% actual size.

E.g., An image which is 2" x 2" and 200 dpi would be scaled to 144 px x 144 px.
And an image which is 1" x 1" and 400 dpi would also be scaled to 72 px x 72 px (even though it has the same pixel dimension as the first image).
 
dpi doesn't matter

144px is 144px no matter what the 'dpi' and the physical dimension on a monitor is dependent on the size of each pixel.

The resolution of an image is it's size in pixels by width and height, not the mythical 'dpi' setting.

--
Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.


 
dpi doesn't matter on screen

There may be another application at play here.

But yes, 72 dpi (or better, ppi) is a myth.
 
I guess I wasn't clear enough.

The physical size I am referring to is the printed size (in inches) of the original files before they are uploaded.

I am trying to maintain the relative physical sizes of uploaded images regardless of their original resolutions.

dpi is not a myth when an image is printed--the same image prints different sizes depending on the dpi setting (assuming the pixel dimensions are left unchanged).

So . . .

An image which is 2" x 2" and 200 dpi (as measured in Photoshop before uploading) would be scaled to 144 px x 144 px.

And an image which is 1" x 1" and 400 dpi (as measured in Photoshop before uploading) would also be scaled to 72 px x 72 px (even though both images are originally 400 px x 400 px).

That way the 2" x 2" image will be twice as big on screen as the 1" x 1" image--same ratio as the printed images. Yeah, yeah, I know that the screen sizes will differ according to monitor resolution, but the the ratio is what I am interested in.
 
Correction: second to last paragraph shouldn't've had "also" in it.
 
So, once an image is uploaded, is the original resolution information destroyed or is there a way of retrieving it?
 
i still think resolution is a misnomer.

but if photoshop or whatever stores the 'resolution' in the exif information it is still available to php. otherwise i can't see why the information would later be useful to an image manipulation program (which would deal purely in pixels). assuming an even distribution of pixels (fair enough) the pixel ratio should be the same as the size ratio, however.
 
if photoshop or whatever stores the 'resolution' in the exif information it is still available to php."

Okay, so how do I get at it?


 
Thanks jpadie for pointing me in the right direction (EXIF). I couldn't get exif_read_data to retrieve image resolution, but the code linked to below did the trick (and got a lot more info about the image):


x and y resolution then retrieved like so:

Code:
include("exif.php");
$path="myimage.jpg";
$verbose = 0;
$result = read_exif_data_raw($path, $verbose);	
$x_res = $result[IFD0][xResolution]
$y_res = $result[IFD0][yResolution]
 
Don't forget that almost all image manipulation software will remove the EXIF data. If the EXIF data is retained during image manipulation it will no longer be true (at least as far as original image size is concerned).

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
almost all image manipulation software will remove the EXIF data"

Yeah, I was concerned about that, but I tested Photoshop CS3 (which is what all the images are processed in) and it seemed to be okay. The EXIF resolution changed appropriately when changing resolutions in Photoshop.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top