Solved

Determine the DPI of a tiff image

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
htacces issue 2 41
Wordpress type image upload 10 32
html input clean up 3 32
using hash in login 34 21
These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now