Code:
<?php
/* what we can handle */
$imgtype = array(1 => 'gif', 'jpeg', 'png', 'swf', 'psd', 'bmp', 'tiff',
'tiff', 'jpc', 'jp2', 'jpx', 'jb2', 'swc', 'iff', 'wbmp', 'xbm');
$img = stripslashes($_GET['img']);
$thumb = $_GET['thumb'];
$small = $_GET['small'];
/* we can generate two sorts of thumbs basically, big and small ones- like two step preview */
$sm = ($small) ? "sm_" : "";
/* append to thumbnail filename */
$type = $_GET['type'];
/* about this later, nifty xsl safeguard */
/* what we do for images with question mark in name? first strip it, then get it back! */
if (isset($img)) $img = str_replace("=63", "?", $img);
else die("No image set for displaying");
function updateThumb() {
global $imgtype, $mimetype, $img, $thumbnail,
$maxwidth, $maxheight, $width, $height;
if ($width > $maxwidth) {
$newwidth = $maxwidth;
(int) $newheight = ( $maxwidth / $width ) * $height;
} else {
$newwidth = $width;
$newheight = $height;
}
if ($newheight > $maxheight) {
$newheight = $maxheight;
(int) $newwidth = ( $maxheight / $height ) * $width;
};
$newimage = imagecreatetruecolor($newwidth, $newheight);
switch($mimetype) {
case 1:
$content = @imagecreatefromgif("$img");
break;
case 2:
$content = @imagecreatefromjpeg("$img");
break;
case 3:
$content = @imagecreatefrompng("$img");
break;
case 7:
case 8:
$content = @imagecreatefromtiff("$img");
break;
default:
/* change me!*/
$content = shell_exec("/usr/bin/convert $img png:-");
$content = imagecreatefromstring("$content");
break;
};
if ($content) {
imagecopyresampled( $newimage, $content, 0, 0, 0, 0,
$newwidth, $newheight, $width, $height );
imagedestroy($content);
};
imagejpeg($newimage, $thumbnail, 92);
imagedestroy($newimage);
}
/*edit me */
function doHTML($img, $base) {
include "messages.txt";
global $masterpath, $headername, $footername;
$tmpimg = "$masterpath/$img";
list($width, $height, $mimetype) = getimagesize("$tmpimg");
$exifdata = @exif_read_data("$tmpimg", "EXIF");
include "$headername";
echo "
<div id=\"imagearea\">
<img src=\"".$_SERVER['PHP_SELF']."?img=$img&type=$base\"
style=\"margin: auto\" title=\"$img\" alt=\"$img - full size\"/>
</div>
<div class=\"data\" id=\"imageData\">";
/* if you have any information about image in accompanying text file...*/
if (file_exists("$masterpath/$img.txt")) {
$myText = file_get_contents("$masterpath/$img.txt");
$myText = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]",
"<a href=\"\\0\">\\0</a>", $myText);
$myText = nl2br($myText);
echo "<div class=\"normaltext\">$myText</div><hr />";
unset($myText);
}
echo "
<b class=\"label\" style=\"width: 100%\">$tmpimg</b><br />
$filesize: " . filesize($tmpimg) . " $bytes, $img_res $width"."x$height<br />";
echo "$Modified (GMT): " . date("Y:m:d G:i", filemtime($tmpimg));
/* exif time- replace "$img_" strings with plaintext, normally I'm using "localised" text */
if ($exifdata) {
if ($exifdata[ExposureTime]) {
$exposuretime = split("/", $exifdata[ExposureTime]);
if (($exposuretime[0] == 10) &&
($exposuretime[1] % 10 == 0)) {
$exposuretime = "1/" . ($exposuretime[1] / 10);
} else if ($exposuretime[0] % $exposuretime[1] == 0) {
$exposuretime = ($exposuretime[0] / $exposuretime[1]);
} else $exposuretime = $exifdata[ExposureTime];
}
echo "<br />
EXIF: $ctime: ";
echo ($exifdata[DateTime]) ? $exifdata[DateTime] : $exifdata[DateTimeOriginal];
echo "<br />
EXIF: $img_ores: $exifdata[ExifImageWidth]x$exifdata[ExifImageLength],
DPI: x=".(int) $exifdata[XResolution]." y=".(int) $exifdata[YResolution]."<br />
EXIF: $img_caminfo: $exifdata[Make] $exifdata[Model]<br />";
if (isset($exifdata[ExposureBiasValue])) {
$tmpnum = split("/", "$exifdata[ExposureBiasValue]");
$tmpevbias = $tmpnum[0] / $tmpnum[1];
}
if (!isset($shortexif)) {
echo "
EXIF: ";
if (isset($exifdata[ExposureProgram])) {
$tmpnum = $exifdata[ExposureProgram];
echo "$img_exposureprog: $img_exposureprogt[$tmpnum], ";
}
echo "$img_exposuretime: $exposuretime"."s,<br />";
if (isset($tmpevbias)) printf("EXIF: %s: %+.2f, ", $img_evbias, $tmpevbias);
echo "ISO $exifdata[ISOSpeedRatings];<br />";
if (isset($exifdata[Flash])) {
$tmpnum = $exifdata[Flash];
echo "
EXIF: $img_flasht[$tmpnum];<br />";
}
echo "
EXIF: $img_focallength: ". ($exifdata[FocalLength] / 10) . "mm,
$img_aperture: ". $exifdata[COMPUTED][ApertureFNumber] .",
$img_digitalzoom: ". ($exifdata[DigitalZoomRatio] / 100). "x;<br />";
} else {
echo "EXIF: ISO $exifdata[ISOSpeedRatings], ";
if (isset($tmpevbias)) printf("EV: %+.2f, ", $tmpevbias);
if ($exposuretime) echo "t=$exposuretime, ";
echo $exifdata[COMPUTED][ApertureFNumber] .", f=".
($exifdata[FocalLength] / 10) . "mm, D=".
($exifdata[DigitalZoomRatio] / 100). "x.";
}
}
echo "</div>";
include "$footername";
}
/* this is cross-site linking safeguard, also simple mean to use the same script for multiple galleries */
$query_string = explode("?", $_SERVER['HTTP_REFERER']);
$basename = basename($query_string[0],
stristr($query_string[0], ".htm"));
unset($query_string);
if (!isset($headername)) $headername = "header.inc";
if (!isset($footername)) $footername = "footer.inc";
if (!file_exists("$basename.conf")) {
if (!$type) {
include $headername;
echo "
<div style=\"text-align:left\">
<h2 class=\"bigtitle\">Configuration file for viewer is not present or<br />
configuration directive has not been specified.<p />
Cannot continue - bailing out.</h2>
Called from $basename (".stristr($_SERVER['HTTP_REFERER'], ".htm") ."
</div>";
include $footername;
exit();
} else {
include "$type.conf";
$myfile = "$type.conf";
}
} else {
include "$basename.conf";
$myfile = "$basename.conf";
}
$scaling_needed = false;
$update_needed = false;
if ($thumb) {
$tmpimg = $img;
$img = "$masterpath/$img";
$mysize = filesize("$img");
$thumbnail = "$cache/$sm$tmpimg-$mysize";
if (getimagesize("$img")) {
list($width, $height, $mimetype) = getimagesize("$img");
if (($width > $maxwidth) || ($height > $maxheight))
$scaling_needed = true;
} else {
header("HTTP/1.0 404 Not found");
die();
}
$dirpath = dirname($thumbnail);
if (!is_dir($dirpath)) mkdir($dirpath);
if ((!file_exists($thumbnail)) || (filemtime($img) > filemtime($thumbnail)) ||
(filemtime($_SERVER[SCRIPT_FILENAME]) > filemtime($thumbnail)) ||
(filemtime($myfile) > filemtime($thumbnail))) {
$update_needed = true;
}
if ($scaling_needed) {
if ($update_needed) updateThumb();
header("Content-type: image/jpeg");
header('Content-transfer-encoding: binary');
readfile($thumbnail);
} else {
if (getimagesize("$img")) {
header("Content-type: image/$imgtype[$mimetype]");
header('Content-transfer-encoding: binary');
header('Content-length: '.filesize($img));
readfile($img);
} else {
header("HTTP/1.0 404 Not found");
die();
}
}
} else {
if (!file_exists("$masterpath/$img")) {
$mypath = dirname("$img");
header("Location: http://rambo.id.uw.edu.pl/viewer.html?path=$mypath");
} else {
/* S A F E G U A R D ! ! ! */
if ($type) {
if ($_SERVER['HTTP_REFERER'] && !isset($_GET[wrap])) {
include "$type.conf";
$img = "$masterpath/$img";
if(@getimagesize("$img")) {
list($garbage, $garbage, $mimetype) = getimagesize("$img");
header("Content-type: image/$imgtype[$mimetype]");
header('Content-transfer-encoding: binary');
header('Content-length: '.filesize($img));
readfile($img);
} else {
header("HTTP/1.0 404 Not found");
die();
}
} else {
doHTML($img, $type);
}
} else {
if ($_SERVER['HTTP_REFERER']) {
doHTML($img, $basename);
}
}
}
};
?>
syntax: ?img=path/image&type=config&thumb=[0|1]&small=[0|1]
Bookmarks