Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Determine the DPI of a tiff image

Posted on 2003-10-23
5
Medium Priority
?
1,771 Views
Last Modified: 2012-05-04
Hi everybody,
is it possible to get the dpi resolution of a tiff image in php?
I know there's a php extension for imagemagick but this means to recompile php.
I think thats a huge effort for only wanting to know the dpi resolution of an image.

Thanks for any suggestion.
Greetings, -ulf-
0
Comment
Question by:ulf_k
  • 3
  • 2
5 Comments
 
LVL 8

Expert Comment

by:inq123
ID: 9608321
Hi ulf_k,

What do you mean by "DPI resolution"?  I thought DPI only applies to printers?

If you want to know the dimension of the image, use getimagesize().  It even returns color depth.  Here's what it returns (quoted from php documentation):

"Returns an array with 4 elements. Index 0 contains the width of the image in pixels. Index 1 contains the height. Index 2 is a flag indicating the type of the image: 1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP, 7 = TIFF(intel byte order), 8 = TIFF(motorola byte order), 9 = JPC, 10 = JP2, 11 = JPX, 12 = JB2, 13 = SWC, 14 = IFF. These values correspond to the IMAGETYPE constants that were added in PHP 4.3. Index 3 is a text string with the correct height="yyy" width="xxx" string that can be used directly in an IMG tag.

With JPG images, two extra indexes are returned: channels and bits. channels will be 3 for RGB pictures and 4 for CMYK pictures. bits is the number of bits for each color.

Beginning with PHP 4.3, bits and channels are present for other image types, too."


Cheers!
0
 

Author Comment

by:ulf_k
ID: 9612624
Hi,
I know getimagesize() and it's output.
But TIFF images also store the resolution in DPI in their header. Thats what i want to retrieve.

-ulf-
0
 
LVL 8

Accepted Solution

by:
inq123 earned 400 total points
ID: 9613007
I c.  For that your best bet would be to use exif_read_data() which reads header from jpeg and tiff.  Then you can dump the content of header out and see DPI info is under which tag.  Again, here's the example from documentation, and you only need to change jpg to tiff I believe.  If this still doesn't work for you, I'm almost sure there's no image function in php that would work for you since if you search php doc with "DPI" it only appears once in a printing description page.  Note that your PHP should be compiled with --enable-exif to have exif_read_data to work.

<?php
echo "test1.jpg:<br />\n";
$exif = exif_read_data ('tests/test1.jpg','IFD0');
echo $exif===false ? "No header data found.<br />\n" : "Image contains headers<br />";
$exif = exif_read_data ('tests/test2.jpg',0,true);
echo "test2.jpg:<br />\n";
foreach($exif as $key=>$section) {
    foreach($section as $name=>$val) {
        echo "$key.$name: $val<br />\n";
    }
}?>
0
 

Author Comment

by:ulf_k
ID: 9614160
Great, this worked.
Many thanks for this solution!!
Greetings, -ulf-
0
 
LVL 8

Expert Comment

by:inq123
ID: 9615603
Glad that I could help!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question