2
/* ----------------------------------------------------------------
3
Script coming with JonDesign's SmoothGallery (http://smoothgallery.jondesign.net).
5
It is an adapted version of
6
http://sneak.co.nz/2006/10/27/dynamic-image-resizing/
7
which is itself an improvement of the original script from
8
Timothy Crowe's 'veryraw' website, with caching additions added by Trent Davies:
9
http://veryraw.com/history/2005/03/image-resizing-with-php/
12
Tim Novinger for finding the image extension problem (fixed by an strtolower())
13
---------------------------------------------------------------- */
17
if (isset($_GET["imgfile"]))
19
if (function_exists(get_magic_quotes_gpc) && get_magic_quotes_gpc())
21
$image = stripslashes( $_GET["imgfile"] );
22
} else $image = $_GET["imgfile"];
23
if (isset($_GET["max_width"])) { if($_GET["max_width"] < 2000) $max_width = $_GET["max_width"]; }
24
if (isset($_GET["max_height"])) { if($_GET["max_height"] < 1000) $max_height = $_GET["max_height"]; }
26
if (strrchr($image, '/')) {
27
$filename = substr(strrchr($image, '/'), 1); // remove folder references
32
$size = getimagesize($image);
36
// get the ratio needed
37
$x_ratio = $max_width / $width;
38
$y_ratio = $max_height / $height;
40
// if image already meets criteria, load current values in
41
// if not, use ratios to load new size info
42
if (($width <= $max_width) && ($height <= $max_height) ) {
45
} else if (($x_ratio * $height) < $max_height) {
46
$tn_height = ceil($x_ratio * $height);
47
$tn_width = $max_width;
49
$tn_width = ceil($y_ratio * $width);
50
$tn_height = $max_height;
53
/* Caching additions by Trent Davies */
55
// cache must be world-readable
56
$resized = 'cache/'.$tn_width.'x'.$tn_height.'-'.$filename;
57
$imageModified = @filemtime($image);
58
$thumbModified = @filemtime($resized);
60
header("Content-type: image/jpeg");
62
// if thumbnail is newer than image then output cached thumbnail and exit
63
if($imageModified<$thumbModified) {
64
header("Last-Modified: ".gmdate("D, d M Y H:i:s",$thumbModified)." GMT");
70
$ext = strtolower(substr(strrchr($image, '.'), 1)); // get the file extension
73
$src = imagecreatefromjpeg($image) or notfound();
76
$src = imagecreatefrompng($image) or notfound();
79
$src = imagecreatefromgif($image) or notfound();
86
$dst = imagecreatetruecolor($tn_width,$tn_height);
88
imageantialias ($dst, true);
90
// copy resized image to new canvas
91
imagecopyresampled ($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height);
93
/* Sharpening adddition by Mike Harding */
94
// sharpen the image (only available in PHP5.1)
95
/*if (function_exists("imageconvolution")) {
96
$matrix = array( array( -1, -1, -1 ),
98
array( -1, -1, -1 ) );
102
imageconvolution($dst, $matrix, $divisor, $offset);
105
// send the header and new image
106
imagejpeg($dst, null, 90);
107
imagejpeg($dst, $resized, 90); // write the thumbnail to cache as well...
109
// clear out the resources
b'\\ No newline at end of file'