Location: PHPKode > projects > PHP Navigator > navphp4.39/images/thumb.php
<?php
#=================================
#  PHP Navigator 3.2
#  Coded by: Cyril Sebastian
#  9:36 PM; August 16, 2006	
#  http://navphp.sourceforge.net
#=================================

$dir = $_REQUEST['dir'];
$file=$_REQUEST['file'];

include_once("../config.php");
include_once("../functions.php");

//---------Thumbnail generator-------------
authenticate();

$src_file = "$dir/$file";
$x = $_GET['size'];
if(!$x) $x=32;

$imginfo = @getimagesize($src_file);
if(!$imginfo) die();

if(!extension_loaded('gd'))  @dl('gd.so');
if(!extension_loaded('gd')) 
	{header("Content-type: image/gif"); print file_get_contents("nogd.gif"); die();}

$srcX = $imginfo[0];
$srcY = $imginfo[1];
$type = $imginfo[2];

if($srcX<$x) $destX = $srcX;
else $destX = $x;
if($srcY<$x) $destY = $srcY;
else $destY = $x;

if(filesize($src_file)>1000000)
	{
	print file_get_contents("exceeds.gif");
	die();
	}

switch($type)
    {
        case 1:
            if(function_exists('imagecreatefromgif'))
                $srcImage = imagecreatefromgif($src_file);
            break;
        case 2:
            if(function_exists('imagecreatefromjpeg'))
                $srcImage = imagecreatefromjpeg($src_file);
            break;
        case 3:
            if(function_exists('imagecreatefrompng'))
                $srcImage = imagecreatefrompng($src_file);
            break;
        case 15:
            if(function_exists('imagecreatefromwbmp'))
                $srcImage = imagecreatefromwbmp($src_file);
            break;
    }

$destImage = imagecreatetruecolor($x, $x);
$white= imagecolorallocate($destImage, 255, 255, 255);
imagefill( $destImage, 0, 0, $white);

imagecopyresampled($destImage, $srcImage, ($x-$destX)/2, ($x-$destY)/2, 0, 0,  $destX, $destY, $srcX, $srcY);
$grey = imagecolorallocate($destImage, 175, 175, 175);
imagerectangle($destImage, 0, 0,$x-1, $x-1, $grey);

if (function_exists("imagegif")) {
    header("Content-type: image/gif");
    imagegif($destImage);
}elseif (function_exists("imagejpeg")) {
    header("Content-type: image/jpeg");
    imagejpeg($destImage, "", 30);
} elseif (function_exists("imagepng")) {
    header("Content-type: image/png");
    imagepng($destImage);
} elseif (function_exists("imagewbmp")) {
    header("Content-type: image/vnd.wap.wbmp");
    imagewbmp($destImage);
} else {
    print file_get_contents("nogd.gif");
}

@imagedestroy($srcImage);
@imagedestroy($destImage);
@imagedestroy($image);
?>

Return current item: PHP Navigator