Contents of file 'viewimg.php':
1 <?php
2 //============================================================================
3 // File: viewimg.php [PHP script]
4 // Created: December 25, 2010 [v.1.0]
5 // Last change: December 25, 2010 [v.1.0]
6 // Author: Fredrik Jonsson <http://jonsson.eu/>
7 //
8 // DESCRIPTION
9 // The VIEWIMG PHP script generates XHTML(a) code for displaying images and
10 // corresponding titles and captions, wrapped in a <div> block which maintains
11 // the visual appearance of the page. The script also attempts to extract any
12 // present Exif(b) information encoded in the images, such as exposure time,
13 // aperture, date and time of original exposure.
14 // Typically, the images displayed with the VIEWIMG script are more
15 // detailed images relayed via common '<a href="larger_image.jpg">Click
16 // for larger image</a>' blocks, but with the advantage that the image is
17 // displayed within the context of the actual webpage, without relying on
18 // any Java scripts for dynamic change of page contents. The XHTML code
19 // generated by the VIEWIMG script conforms to the XHTML 1.0 Strict
20 // specification and makes sure that any special characters present in the
21 // code are properly html:icized before display.
22 //
23 // (a) XHTML = Extensible HyperText Markup Language, a markup language that
24 // has the same expressive possibilities as HTML, but in stricter syntax.
25 // (b) Exchangeable image file format.
26 //
27 // USAGE
28 // Put the following block into the web page where you would like to display
29 // the image (using the default "en" language option):
30 //
31 // < ? php include "/php/viewimg.php"; viewimg("en"); ? >
32 // <rest of your (X)HTML code for the page>
33 //
34 // Here, the "en" (for English) may be replaced by "sv" (for Swedish).
35 // In similar to the VIEWSRC script, the VIEWIMG() block will remain silent
36 // without any action until a valid MD5 checksum appears as input value to
37 // the 'viewimg' parameter in the URI. If the checksum is found to match that
38 // of a valid file in the list of images allowed for display, this will
39 // generate a full-width single-column page (still maintaining the same
40 // graphical appearance of the original page) which displays the enlarged
41 // image. Example of a valid URI employing VIEWIMG, where the input value
42 // ("378...ed") is the MD5 checksum of the filename
43 // 'nymet-mirror-20101022-700x525.jpg':
44 //
45 // http://jonsson.eu/about/?viewimg=37849c4ca405247edccd0ea47bf2b8ed
46 //
47 // The viewimg() script will then typically generate (X)HTML output of the
48 // following form:
49 //
50 // <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
51 // "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
52 // <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
53 // <body id="oneColLayout">
54 // <div id="imageView">
55 // <img src="nymet-mirror-20101022-700x525.jpg"
56 // alt="nymet-mirror-20101022-700x525.jpg" />
57 // <p>
58 // <b>Facet mirror.</b> Mirror in the section of Modern Arts,
59 // the <a href="http://www.metmuseum.org">Metropolitan Museum
60 // of Art,</a> New York.
61 // </p>
62 // <p>
63 // <span class="EXIFData">Date: 22 October 2010. Exposure: 10/200 s,
64 // f/3.5. Camera: SONY DSC-T30.
65 // </span>File: <a href="nymet-mirror-20101022-700x525.jpg">
66 // nymet-mirror-20101022-700x525.jpg</a><br/>
67 // </div> <!-- End of imageView div -->
68 // </body>
69 // </html>
70 //
71 // DEPENDENCIES
72 // For proper operation, the VIEWIMG script relies on the presence of the
73 // following PHP scripts, available at http://jonsson.eu/programs/php/:
74 //
75 // prevpage.php [http://jonsson.eu/programs/php/prevpage/]
76 // htmlicise.php [http://jonsson.eu/programs/php/htmlicise/]
77 // footer.php [http://jonsson.eu/programs/php/footer/]
78 //
79 // PARAMETERS
80 // The user-end interface to the routine is the function viewimg($lang), in
81 // which the $lang parameter specifies which language to use for headers.
82 // Currently only two choices are valid: "en" (English) or "sv" (Swedish).
83 //
84 // CONFIGURATION
85 // Any image to be displayed by the VIEWIMG script must first be entered into
86 // the list of allowed files. This way, no image except the allowed ones may
87 // be displayed, implying that no file which otherwise is hidden by the PHP
88 // engine (such as password files or other files containing sensitive
89 // information) can be accessed. This list of allowed files is declared
90 // globally in the user-customizable section immediately below.
91 //
92 // Copyright (C) 2010-2011, Fredrik Jonsson <http://jonsson.eu/>
93 // Non-commercial copying welcome.
94 //============================================================================
95 //
96 // ###########################################################################
97 // ######## CUSTOMIZE THE FOLLOWING PARAMETERS WITH YOUR OWN SETTINGS ########
98 // ######## FOR DETAILS, SEE CONFIG INSTRUCTIONS IN THE HEADER ABOVE #########
99 // ###########################################################################
100 //
101 // Define which EXIF parameters to extract and display in the image caption.
102 // Here 'true'=display, 'false'=do not display
103 //
104 $displayDateOfExposure=true; // Display original date of exposure
105 $displayExposureData=true; // Display shutter speed and f-number used
106 $displayCameraMakeModel=true; // Display make and model of camera used
107
108 //
109 // Define the images allowed for display by the VIEWIMG script. These are set
110 // as global-level character strings which are accessed by $GLOBALS[...].
111 //
112 // All images valid for viewing are here hardcoded as a list directly in the
113 // PHP source, to avoid any potential security issues from loading data from
114 // external files (unless these files are already protected by the PHP
115 // engine, that is to say). For further details, see "PHP in a Nutshell" by
116 // Paul Hudson (O'Reilly, 2005).
117 //
118 $viewimage_allowedfiles[1]="nymet-20101022-rotated-233x233.jpg";
119 $viewimage_title[1]="Self portrait.";
120 $viewimage_caption[1]="Mirror in the section of Modern Arts, the ".
121 "<a href=\"http://www.metmuseum.org\">Metropolitan Museum of Art.</a>.";
122 // ----
123 $viewimage_allowedfiles[2]="nymet-20101022-rotated-700x700.jpg";
124 $viewimage_title[2]="Self portrait.";
125 $viewimage_caption[2]="Mirror in the section of Modern Arts, the ".
126 "<a href=\"http://www.metmuseum.org\">Metropolitan Museum of Art.</a>".
127 "Makes you curious? This is what the ".
128 "<a href=\"?viewimg=".md5("nymet-mirror-20101022-700x525.jpg")."\">mirror ".
129 "looks like</a>.";
130 // ----
131 $viewimage_allowedfiles[3]="nymet-20101022-rotated-3061x3061.jpg";
132 $viewimage_title[3]="Self portrait.";
133 $viewimage_caption[3]="Mirror in the section of Modern Arts, the ".
134 "<a href=\"http://www.metmuseum.org\">Metropolitan Museum of Art.</a>".
135 "Makes you curious? This is what the ".
136 "<a href=\"?viewimg=".md5("nymet-mirror-20101022-700x525.jpg")."\">mirror ".
137 "looks like</a>.";
138 // ----
139 $viewimage_allowedfiles[4]="nymet-mirror-20101022-700x525.jpg";
140 $viewimage_title[4]="Facet mirror.";
141 $viewimage_caption[4]="Mirror in the section of Modern Arts, the ".
142 "<a href=\"http://www.metmuseum.org\">Metropolitan Museum of Art,</a> ".
143 "New York.";
144 //
145 // ###########################################################################
146 // ######## END OF USER CUSTOMIZABLE PARAMETERS ##############################
147 // ###########################################################################
148 //
149
150 function viewimage_display_exif_data($filename) {
151 //
152 // Read any EXIF data encoded in the image, using the built-in PHP function
153 // as described at http://uk2.php.net/exif_read_data. This requires a PHP
154 // version above 4.20, and also that the EXIF extension was included in the
155 // compilation. Hence, the following block of code starts with a verification
156 // that the function exif_read_data() is available in the first place;
157 // otherwise the EXIF extraction is ignored.
158 //
159 if (function_exists("exif_read_data")) {
160 $exif = exif_read_data($filename,0,true);
161 //========================================================================
162 // In order to display the entire set of EXIF data encoded in the image
163 // file, uncomment the following block:
164 // foreach ($exif as $key => $section) {
165 // foreach ($section as $name => $val) {
166 // echo "$key.$name: $val<br />\n";
167 // }
168 // }
169 //========================================================================
170 $cameraMake=$exif['IFD0']['Make'];
171 $cameraModel=$exif['IFD0']['Model'];
172 $originalExposureTimeStamp=$exif['EXIF']['DateTimeOriginal'];
173 $originalExposureTimeStamp=explode(":",$originalExposureTimeStamp);
174 $originalExposureYear=$originalExposureTimeStamp[0];
175 $originalExposureMonth=$originalExposureTimeStamp[1];
176 $originalExposureDateHour=explode(" ",$originalExposureTimeStamp[2]);
177 $originalExposureDate=$originalExposureDateHour[0];
178 $originalExposureHour=$originalExposureDateHour[1];
179 $originalExposureMinute=$originalExposureTimeStamp[3];
180 $originalExposureSecond=$originalExposureTimeStamp[4];
181 $originalExposureTimeStamp=strtotime("$originalExposureMonth/"
182 ."$originalExposureDate/$originalExposureYear");
183 $originalExposureTimeStamp=date('d F Y',$originalExposureTimeStamp);
184 $exposureTime=$exif['EXIF']['ExposureTime'];
185 $apertureFNumber=$exif['COMPUTED']['ApertureFNumber'];
186 echo "<span class=\"EXIFData\">";
187 if ($GLOBALS['displayDateOfExposure']==true)
188 echo "Date: $originalExposureTimeStamp. ";
189 if ($GLOBALS['displayExposureData']==true)
190 echo "Exposure: $exposureTime s, $apertureFNumber. ";
191 if ($GLOBALS['displayCameraMakeModel']==true)
192 echo "Camera: $cameraMake $cameraModel. ";
193 echo "</span>";
194 }
195 return;
196 }
197
198 function viewimg($lang) {
199 if (($md5hash=$_GET["viewimg"])!="") {
200 $platform=$_SERVER['SERVER_SOFTWARE'];
201 if ((strpos($platform,"Microsoft")!==false)
202 &&(strpos($platform,"IIS")!==false)) {
203 $siteroot="e:\\jonsson";
204 } else {
205 $siteroot=$_SERVER['DOCUMENT_ROOT'];
206 }
207 include_once $siteroot."/php/prevpage.php";
208 include_once $siteroot."/php/footer.php";
209 include_once $siteroot."/php/emailform.php";
210 $num_allowed_files=count($GLOBALS['viewimage_allowedfiles']);
211 $file_to_view="";
212 for ($k=1;$k<=$num_allowed_files;$k++) {
213 if (!strcmp(trim($md5hash),
214 md5(trim($GLOBALS['viewimage_allowedfiles'][$k])))) {
215 $file_to_view=trim($GLOBALS['viewimage_allowedfiles'][$k]);
216 $viewimage_title_to_display=trim($GLOBALS['viewimage_title'][$k]);
217 $viewimage_caption_to_display=trim($GLOBALS['viewimage_caption'][$k]);
218 }
219 }
220 echo "<div id=\"imageView\">\n";
221 if ($file_to_view=="") {
222 for ($k=1;$k<=8;$k++) echo "<br />\n";
223 echo "<p class=\"center\"><b>Error: Invalid file ID!</b></p>\n";
224 for ($k=1;$k<=18;$k++) echo "<br />\n";
225 } else {
226 prevpage($lang);
227 }
228 echo "<img src=\"".$file_to_view."\" alt=\"".$file_to_view."\" />\n";
229 echo "<p>\n";
230 echo "<b>".$viewimage_title_to_display."</b> ".
231 $viewimage_caption_to_display."\n";
232 echo "</p>\n";
233 echo "<p>\n";
234 viewimage_display_exif_data($file_to_view);
235 echo "File: <a href=\"".$file_to_view."\">".$file_to_view."</a><br/>\n";
236 echo "</p>\n";
237 echo "<p class=\"viewimg\">\n";
238 $viewimg_url="http://jonsson.eu/programs/php/viewimg/";
239 echo "Generated by <a href=\"".$viewimg_url."\">::viewimg::</a>\n";
240 echo "</p>\n";
241 prevpage($lang);
242 echo "</div> <!-- End of imageView div -->\n";
243 echo "<div class=\"clear\"></div>\n";
244 footer($lang);
245 echo "</div> <!-- End of container div -->\n";
246 echo "</body>\n";
247 echo "</html>\n";
248 exit(0);
249 }
250 }
251 ?>
252
Generated by ::viewsrc::