Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Determine the DPI of a tiff image

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
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.

790 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