<?php
// fb_exif Extension
// by Donald Tetto (with modifications by James Yencken)
// http://folderblog.tetto.org/

if(($page=="main"||$page=="comments") && (function_exists("exif_imagetype"))) {
    $data = exif_read_data($fbimage[1]);
    if(isset($data["ExposureTime"])) {
        list($num,$den) = explode("/",$data["ExposureTime"]);
	    if ($num!=1) { 
            $fbexposure = "{$num}s";}
	    else {
	        $den = $den/$num;   
            $fbexposure = "1/{$den}s";}
    }
    if (isset($data["ISOSpeedRatings"])) {
        $fbiso = $data["ISOSpeedRatings"]; 
    }
    if(isset($data["FNumber"])) {
        list($num,$den) = explode("/",$data["FNumber"]);
        $fbaperture  = "F/" . ($num/$den);
    }
    if(isset($data["FocalLength"])) {
        list($num,$den) = explode("/",$data["FocalLength"]);
        $fbfocallength  = ($num/$den) . "mm";
    }
    if(isset($data["ExposureBiasValue"])) {
        list($num,$den) = explode("/",$data["ExposureBiasValue"]);
        $fbexposurecomp = round(($num/$den),1);
        $fbexposurecomp = ($fbexposurecomp<0 ? "" : "+") . number_format($fbexposurecomp,1) . "ev";
    }
    if(isset($data["WhiteBalance"])) {
        switch($data["WhiteBalance"]) {
            case 0:
                $fbwhitebalance = "Auto";
                break;
            case 1:
                $fbwhitebalance = "Daylight";
                break;
            case 2:
                $fbwhitebalance = "Fluorescent";
                break;
            case 3:
                $fbwhitebalance = "Incandescent";
                break;
            case 4:
                $fbwhitebalance = "Flash";
                break;
            case 9:
                $fbwhitebalance = "Fine Weather";
                break;
            case 10:
                $fbwhitebalance = "Cloudy";
                break;
            case 11:
                $fbwhitebalance = "Shade";
                break;
            default:
                $fbwhitebalance = "";
                break;
        }
    }
}
$tags += array("<#fbcamera#>" => isset($data["Model"]) ? ucwords(strtolower($data["Model"])) : "",
               "<#fbflash#>" => isset($data["Flash"]) ? (bindec($data["Flash"]) ? "On" : "Off") : "",
               "<#fbfocallength#>" => isset($fbfocallength) ? $fbfocallength : "",
               "<#fbexposure#>" => isset($fbexposure) ? $fbexposure : "",
               "<#fbiso#>" => isset($fbiso) ? $fbiso : "",
               "<#fbaperture#>" => isset($fbaperture) ? $fbaperture : "",
               "<#fbwhitebalance#>" => isset($fbwhitebalance) ? $fbwhitebalance : "",
               "<#fbexposurecomp#>" => isset($fbexposurecomp) ? $fbexposurecomp : "",
               "<#fbtaken#>" => isset($data["DateTimeOriginal"]) ? str_replace(":","-",substr($data["DateTimeOriginal"],0,10)) . substr($data["DateTimeOriginal"],10) : "");
?>