aboutsummaryrefslogtreecommitdiff
path: root/www/inc/exif.inc.php
blob: ac30a16ab4b77f6eefd281678986ac8a2de9476a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php


function formatEXIF ($k,$v) {
	// format some special cases
	// dunno if EXIF support formats it so weirdly everywhere.
	// Sure does in my php4

	switch ($k) {
		case "FocalLength":
			$out = eval("return $v;"); 
			$out .= "mm";
			return $out;
			break;
		case "FNumber":
			$out = "f/";
			$out .= eval("return $v;");
			return $out;
			break;
		case "ExposureTime":
			// numerator = cistatel; jmenovatel = denominator :)
			$x = explode("/",$v,2);
			if ($x[0]>=100) {
				$out = eval("return ${x[0]}/${x[1]};");
				$out .= "s";
				return $out;
			} else {
				return "1/".(1.0/($x[0]/$x[1]))."s";
			}
			break;
		case "Flash";
			if ($v=="0") {
				return "No Flash";
			} else {
				return $v;
			}
			break;
		case "ISOSpeedRatings":
			return "ISO" . $v;
			break;
		case "GainControl";
			return "EV" . $v;
			break;
		case "FocalLengthIn35mmFilm":
			return $v . "mm";
			break;
		case "DateTime":
			//return date("M d Y H:i:s", $v);
			preg_match("/^([0-9]{4}):([0-9]{1,2}):([0-9]{1,2}) (.*)/",$v,$x);
			return $x[1] . "/" . $x[2] . "/" . $x[3] . " " . $x[4];
			break;
		default:
			return $v;
	}
}


// Only use php4 internal handling now.
// $file is LQ image
$exif_array = exif_read_data("$file");
reset($exif_array);
if ($exif_show) reset($exif_show);

if ($exif_array["Make"]) { // only render all this 
													// if there is EXIF header
	// fancy table look
	echo "<div id=\"exif_table\" style=\"display: none;\">\n";
	echo "<table class=\"exif\" border=\"0\">\n";
	//co ukazat (podle exif_show)
	if ($exif_show) {
		 while (list($kx,$x) = each($exif_show)) {
			 while(list($k,$v)=each($exif_array)) {
			 if ($kx==$k) {
				 echo "<tr>";
				 echo "<td align=\"right\">";
				 echo $x;
				 echo ": </td>";
				 echo "<td><b>";
				 echo formatEXIF($k,$v);
				 echo "</b></td>";
				 echo "</tr>\n";
			 }
			 }
			 reset($exif_array);
		 }
	} else {
		 //ukaze vsechno v tabulce
		 while(list($k,$v)=each($exif_array)) {
				echo "<tr>";
				echo "<td align=\"right\">";
				echo $k;
				echo ": </td>";
				echo "<td><b>";
				echo formatEXIF($k,$v);
				echo "</b></td>";
				echo "</tr>\n";
		 }
	}
	echo "<tr>\n";
	echo "<td></td>";
	echo "<td><a href=\"javascript:toggle_div('exif_table');toggle_div('exif_line');\">" . __("Less info");
	echo "</a></td>";
	echo "</tr>\n";
	echo "</table>\n";
	echo "</div>\n";





	// selected EXIF header on one line
	echo "<div id=\"exif_line\">\n";
	echo "<p class=\"exif\">";
	reset($exif_array);
	if ($exif_show) reset($exif_show);
	if ($exif_show) {
		 while (list($kx,$x) = each($exif_show)) {
			 while(list($k,$v)=each($exif_array)) {
					 if ($kx==$k) {
							echo "<span title=\"$x\">";
							echo formatEXIF($k,$v);
							echo "</span> | ";
					 }
				}
		 reset($exif_array);
		 }
	} else {
		/* vsechny exif headers inline */
		 while(list($k,$v)=each($exif_array)) {
				echo "<span title=\"";
				echo $k;
				echo "\">";
				echo formatEXIF($k,$v);
				echo "</span> | ";
		 }
	}

	echo "<a href=\"javascript:toggle_div('exif_table');toggle_div('exif_line');\">" . __("More info");
	echo "</a></p>\n";
	echo "</div>\n";
}

?>