Solved

Determine the DPI of a tiff image

Posted on 2003-10-23
5
1,695 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 100 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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How do I make my dropdowns depended within a JQuery Modal Dialog box. 3 29
str_replace not working in php script 4 31
paypal ipn url 5 58
php checkbox validation 5 27
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

809 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