Search:

Source files | Examples | Dependencies | Parameters | Function arguments

VIEWIMG

The VIEWIMG PHP script generates XHTML code for displaying images and corresponding titles and captions, wrapped in a <div> block which maintains the visual appearance of the page. The script also attempts to extract any present Exif information encoded in the images, such as exposure time, aperture, date and time of original exposure. Typically, the images displayed with the VIEWIMG script are more detailed images relayed via common '<a href="larger_image.jpg">Click for larger image</a>' blocks, but with the advantage that the image is displayed within the context of the actual webpage, without relying on any Java scripts for dynamic change of page contents. The XHTML code generated by the VIEWIMG script conforms to the XHTML 1.0 Strict specification and makes sure that any special characters present in the code are properly html:icized before display.

Source files

viewimg.php [11 kB] The entire PHP code for the VIEWSRC script, containing all necessary routines and inclusions of external resources in one single file. Current revision is v.1.8, as of 25/12/2010. Copyright © Fredrik Jonsson 2010-2024, under GNU General Public License
[ download | view source ]

Using the VIEWIMG script

Add the following block into the (X)HTML code for the web page in which you would like to have the the file contents displayed as code (here using the default "en" language option):


     <?php include "viewimg.php"; viewimg("en"); ?>

Here, the "en" (for English) may be replaced by "sv" (for Swedish). In similar to the viewsrc script, the viewimg() block will remain silent without any action until a valid MD5 checksum appears as input value to the 'viewimg' parameter in the URI. If the checksum is found to match that of a valid file in the list of images allowed for display, this will generate a full-width single-column page (still maintaining the same graphical appearance of the original page) which displays the enlarged image. Example of a valid URI employing viewimg, where the input value ("378...ed") is the MD5 checksum of the filename 'nymet-mirror-20101022-700x525.jpg':


     
http://jonsson.eu/about/?viewimg=37849c4ca405247edccd0ea47bf2b8ed

The page you get via this URI is constructed using the following PHP code (with the viewimg blocks emphasized);


     <?php
       $title="....";
       $keywords="....";
       $siteroot=$_SERVER['DOCUMENT_ROOT'];
       if (($lang=$_GET["lang"])=="") $lang=en; // English default
       include $siteroot."/php/pageheader.php";
       include $siteroot."/php/navbar.php";
       include $siteroot."/php/viewsrc.php";
       include $siteroot."/php/viewimg.php";
       include $siteroot."/php/langswitch.php";
       include $siteroot."/php/prevpage.php";
       include $siteroot."/php/footer.php";
       pageheader($lang,$title,$keywords);
     ?>
     <body id="oneColLayout">
     <div id="container">
     <?php
       navbar($siteroot,$lang);
       viewsrc($lang);
       viewimg($lang);
     ?>
     <div id="primaryContent" class="biography" >
     <?php langswitch($lang); ?>
         .    .    .    .
         .    .    .    .
         .    .    .    .
     <?php prevpage($lang); ?>
     </div> <!-- End of primaryContent div -->
     <div id="sideContent">
         .    .    .    .
         .    .    .    .
         .    .    .    .
     </div> <!-- End of sideContent div -->
     <?php footer($lang); ?>
     </div>
     </body>
     </html>

The viewimg() script will then typically generate (X)HTML output of the following form:


     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
     <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
     <body id="oneColLayout">
     <div id="imageView">
     <img src="nymet-mirror-20101022-700x525.jpg"
             alt="nymet-mirror-20101022-700x525.jpg" />
     <p>
     <b>Facet mirror.</b> Mirror in the section of Modern Arts,
     the <a href="http://www.metmuseum.org">Metropolitan Museum
     of Art,</a> New York.
     </p>
     <p>
     <span class="EXIFData">Date: 22 October 2010. Exposure: 10/200 s,
     f/3.5. Camera: SONY DSC-T30.
     </span>File: <a href="nymet-mirror-20101022-700x525.jpg">
     nymet-mirror-20101022-700x525.jpg</a><br/>
     </div> <!-- End of imageView div -->
     </body>
     </html>

Dependencies

For proper operation, the viewimg() function relies on the presence of the following PHP scripts, publicly available at http://jonsson.eu/programs/php/:

Parameters and configuration

All user-customizable parameters of the script are present immediately after the initial header in viewimg.php. The significance of the parameters are as follows:

$displayDateOfExposure

Display original date of exposure (from EXIF parameters) in the caption. Here 'true'='display', 'false'='do not display'. The extraction of EXIF parameters requires the PHP server to run with EXIF Support enabled.

$displayExposureData

Display shutter speed and f-number used (from EXIF parameters) in the caption. Here 'true'='display', 'false'='do not display'. The extraction of EXIF parameters requires the PHP server to run with EXIF Support enabled.

$displayCameraMakeModel

Display make and model of camera used (from EXIF parameters) in the caption. Here 'true'='display', 'false'='do not display'. The extraction of EXIF parameters requires the PHP server to run with EXIF Support enabled.

$viewimage_allowedfiles[...],
$viewimage_title[...],
$viewimage_caption[...]

Arrays defining the files allowed for display by the VIEWIMG script ($viewimage_allowedfiles[...]) and their corresponding text strings to be used as titles ($viewimage_title[...]) and captions ($viewimage_caption[...]). These are set as global-level character strings which are accessed by $GLOBALS[...]. All files valid for viewing are here hardcoded as a list directly in the PHP source, to avoid any potential security issues from loading data from external text files (unless these files are already protected by the PHP engine, that is to say). For further details, see "PHP in a Nutshell" by Paul Hudson (O'Reilly, 2005). Example:


$viewimage_allowedfiles[1]="nymet-20101022-rotated-233x233.jpg";
$viewimage_title[1]="Self portrait.";
$viewimage_caption[1]="Mirror in the section of Modern Arts, ".
  "the <a href=\"http://www.metmuseum.org\">Metropolitan ".
  "Museum of Art.</a>.";

$viewimage_allowedfiles[2]="nymet-20101022-rotated-700x700.jpg";
$viewimage_title[2]="Self portrait.";
$viewimage_caption[2]="Mirror in the section of Modern Arts, ".
  "the <a href=\"http://www.metmuseum.org\">Metropolitan ".
  "Museum of Art.</a> Curious? This is what the ".
  "<a href=\"?viewimg=".md5("nymet-mirror-20101022-700x525.jpg").
  "\">mirror looks like</a>.";

  . . .

Function arguments

In the viewimg($lang) function, the significance of the input argument is as follows.

$lang

Determines the language to use for headers in generation of the quote(s). Accepted values are "en" (for English) or "sv" (for Swedish).

Return to previous page

Leave a message

Your name:

Your email: (required)

Message:

Generated by ::emailform::

Last modified Wednesday 15 Feb 2023
QR code for string http://jonsson.eu/programs/php/viewimg/