These functions power the viewer. Each does what their names suggest: read the EXIF data and store available tags; display the image; print the available data.
PHP Code:
// viewer
function getImg($img) {
global $exif, $tags;
$imgx = imgConfirm($img);
if ($imgx) {
$str = "<img src=\"$imgx\" ";
$chtm =$exif['COMPUTED']['html'];
if (!$chtm) {
$fil_wid = $exif['COMPUTED']['Width'];
$fil_hgt = $exif['COMPUTED']['Height'];
$str .= "width=\"" . (($fil_wid > 0) ? $fil_wid : "100%") . "\" height=\"" . (($fil_hgt > 0) ? $fil_hgt : "100%") . "\"";
} else {
$str .= $chtm;
}
$str .= " alt=\"" . $tags['alt'] . "\" title=\"" . $tags['title'] . "\">";
echo $str;
} else {
echo "Image not found.";
}
}
function readExif($img) {
global $exif, $use_com, $errStr, $tags;
$errStr = "";
$imgx = imgConfirm($img);
if ($imgx) {
if (@exif_read_data($imgx)) {
$exif = @exif_read_data($imgx, 0, true, false);
echo "<div id=\"exifdump\">\n";
print_r($exif);
echo "</div>\n";
$comment = hasSection('COMMENT') ? $exif['COMMENT'][0] : null;
$alt = filter($exif['IFD0']['Subject']);
$title = filter($exif['IFD0']['Title']);
$comments = filter($exif['IFD0']['Comments']);
$author = filter($exif['IFD0']['Author']);
$alt= $alt ? $alt : strTrunc($imgx, 4);
$title = $title ? $title : strTrunc($imgx, 4);
$comments = $comments ? $comments : null;
$author = $author ? $author : null;
$tags = array(
'alt'=> $alt,
'title' => $title,
'author' => $author,
'comments' => $comments,
'comment' => $comment
);
if (hasSection('GPS')) {
$gps = $exif['GPS']['GPSAltitudeRef'];
$alt_ref = ($gps !== null) ? $gps : null;
$tags['altref'] = (int)($alt_ref);
$gps = $exif['GPS']['GPSAltitude'];
$gps_alt = ($gps !== null) ? round(divide($gps), 4) : "N/A";
$tags['altitude'] = $gps_alt;
$gps = getGPS();
if ($gps != null) {
$tags['latitude'] = $gps[0];
$tags['longitude'] = $gps[1];
}
} else {
$errStr .= " <tr>\n<td colspan=\"3\"><p>No GPS tags found.<p></td>\n";
}
} else {
$errStr .= " <tr>\n<td colspan=\"3\"><p>No EXIF tags found.</p></td>\n";
}
}
}
function printData() {
global $errStr, $exif, $tags;
$str = "";
if ($tags['comment']) { $str .= " <tr>\n <td colspan=\"3\">\n <p class=\"comment\">" . $tags['comment'] . "</p>\n </td>\n </tr>\n"; }
if ($tags['comments']) { $str .= " <tr>\n <td colspan=\"3\">\n <p class=\"comment\">" . $tags['comments'] . "</p>\n </td>\n </tr>\n"; }
if (!$errStr) {
$str .= " <tr><th scope=\"col\">LATITUDE</th><th scope=\"col\">LONGITUDE</th><th scope=\"col\">ALTITUDE</th></tr>\n <tr>\n";
$str .= " <td>\n <p>" . $tags['latdeg'] . "° " . $tags['latmin'] . "’ " . $tags['latsec'] . "” " . $tags['lathem'] . "</p>\n <p>" . $tags['latitude'] . "°</p>\n </td>\n";
$str .= " <td>\n <p>" . $tags['logdeg'] . "° " . $tags['logmin'] . "’ " . $tags['logsec'] . "” " . $tags['loghem'] . "</p>\n <p>" . $tags['longitude'] . "°</p>\n </td>\n";
$h = isset($_REQUEST['h']) ? $_REQUEST['h'] : 0;
$z = ((intval($h) <= 4 && intval($h) >= -4) ? "&z=" . (string)(17 + intval($h)) : "&z=17");
$str .= " <td>\n <p>" . (($tags['altitude'] == "N/A") ? $tags['altitude'] : $tags['altitude'] . " m " . (($tags['altref']) ? "Below" : "Above") . " Sea Level.") . "</p>\n <p>Go to this <a href=\"http://www.wikimapia.org/#lat=" . $tags['latitude'] . "&lon=" . $tags['longitude'] . $z . "\">location on the map</a></p>\n </td>\n";
} else {
$str .= $errStr;
}
$str .= " </tr>";
echo $str;
}
//