Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

PHP and Ghraphics

Getting Exif information out of Images. by Karl Blessing
Posted: 16 Dec 04

So you have a photo gallery, and a digital camera. Alot of people are interested to know how the shots were taken or when for that matter. (data such as shutter, aperture, focal length, iso speed, date, etc are stored inside of 99% of images shot with an exif compliant digital camera)

First off have to make sure Exif support was compiled with PHP( linux/unix ), or that the php_exif.dll extension is loaded ( windows ).

The following code pulls the basic information I usally need for my photo gallery (Camera Model, Shutter, Aperture, ISO Speed, And Focal Length)


function get_exif($filename, $gallery)
        return "Exif Support Not Loaded";
/* In my gallery code all my images are under the gallery folder, under a specific gallery, the path below can be changed to where you images are located. */
        $imagepath = $_SERVER['DOCUMENT_ROOT']."/gallery/".$gallery."/".$filename.".jpg";
    /* next line obtains the exif data from the images the second parameter can be changed to 'EXIF' but seems 'IFD0' works fine for the list of information I need */
        @$exif = exif_read_data($imagepath, 'IFD0');                
/* Because manufacture vary , the exif information provided isnt always in the same name, I check to see if at least two of the exif information is not blank, if they are then I assume no valid exif information is present. */

        if (($exif['FNumber'] == "") || ($exif['FocalLength'] == ""))
            return "No EXIF Data";
            @$exif = exif_read_data($imagepath, 'IFD0', true);

//uncomment the next code block, if you wish to see ALL values inside of the exif information, useful for finding the exact keys you want beforehand
            foreach ($exif as $key => $section) {
                foreach ($section as $name => $val) {
                    echo "<!-- $key.$name: $val -->\n";

//convert the raw values to understandible values
            $Fnumber = explode("/", $exif['EXIF']['FNumber']);
            $Fnumber = $Fnumber[0] / $Fnumber[1];
            $Focal = explode("/", $exif['EXIF']['FocalLength']);
            $Focal = $Focal[0] / $Focal[1];

//prepare the text for return        
            $exif_text = "Model: ".$exif['IFD0']['Model']."<br>";
            $exif_text = $exif_text."Shutter: ".$exif['EXIF']['ExposureTime']."<br>";
            $exif_text = $exif_text."Aperture: f/".$Fnumber."<br>";
            $exif_text = $exif_text."ISO Speed: ".$exif['EXIF']['ISOSpeedRatings']."<br>";
            $exif_text = $exif_text."Focal Length: ".round($Focal)."mm<br>";
            return $exif_text;

Back to PHP FAQ Index
Back to PHP Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close