Location: PHPKode > scripts > Particle Gallery > generators/preview.php
<?php
require("../includes/global.php");

$sql = "SELECT * FROM " . $dbprefix . "images WHERE imageid = " . intval($_GET["imageid"]);
$img = $db->execute($sql);
if ($img->rows < 1){ notfound(); }

// support for non-GD users
function default_thumb(){
	redirect("original.php?imageid=" . $img->fields["imageid"]);
}

// check for GD support and fopen wrapters
if ($gd === FALSE){ default_thumb(); }
if (ini_get("allow_url_fopen") == 0){ default_thumb(); }
if (ini_get("safe_mode") == 1){ default_thumb(); }

// work out thumbnail size
$size_cng = intval($config["previewsize"]);
if ($size_cng < 1){ default_thumb(); }

// create a temperory file
$filepath = str_replace("preview", "original", "http://" . $_SERVER["SERVER_NAME"] . $_SERVER["PHP_SELF"]);
$imageFile = file_get_contents($filepath . "?imageid=" . $img->fields["imageid"]);
$tmpname = tempnam("/tmp", "");
$fp = fopen($tmpname, "w");
fwrite($fp, $imageFile);
fclose($fp);

// thumbnail size
//$thumbsize = intval($config["thumbnailsize"]);
$thumbsize = $size_cng;
$thumbsize = ($thumbsize < 10) ? 100 : $thumbsize;

// create variables
$size = GetImageSize($tmpname);
if ($size[0] < $thumbsize && $size[1] < $thumbsize){
	$thumbnail_width = $size[0];
	$thumbnail_height = $size[1];
} elseif($size[0] > $size[1]){
	$thumbnail_width = $thumbsize;
	$thumbnail_height = (int)($thumbsize * $size[1] / $size[0]);
} else {
	$thumbnail_width = (int)($thumbsize * $size[0] / $size[1]);
	$thumbnail_height = $thumbsize;
}

// create functions
$function_suffix = $gd_function_suffix[$img->fields["format"]];
$function_to_read = 'ImageCreateFrom' . $function_suffix;
$function_to_write = 'Image' . $function_suffix;

if (!(function_exists($function_to_read))){ default_thumb(); }
if (!(function_exists($function_to_write))){ default_thumb(); }

$source_handle = $function_to_read($tmpname);
$destination_handle = ImageCreateTrueColor($thumbnail_width, $thumbnail_height);
ImageCopyResampled($destination_handle, $source_handle, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $size[0], $size[1]);

// output content
Header("Content-type: " . $img->fields["format"]);
$function_to_write($destination_handle);

// and delete the tmp line
unlink($tmpname);
?>
Return current item: Particle Gallery