CREATE & RESIZE PIC WITH THUMBNAIL



You have to create a folder (subdirectory) called thumbs and another called pics or replace the code in red with your folders name

<?
$picfile=$_FILES['file']['name'];

$ext = substr($picfile,-3);
$ext = strtolower($ext);

if(($ext=="gif") OR ($ext=="jpg") OR ($ext=="png"))
{

// CREATING & RESIZING THUMBNAIL TO 150 px WIDE

$uploadedfile = $_FILES['file']['tmp_name'];

if($ext=="gif"){$src = imagecreatefromgif($uploadedfile);}
if($ext=="jpg"){$src = imagecreatefromjpeg($uploadedfile);}
if($ext=="png"){$src = imagecreatefrompng($uploadedfile);}


list($width,$height)=getimagesize($uploadedfile);


// Setting the thumbnail to be 150 pixels wide,
$newwidth=150;
$newheight=($height/$width)*150;
$tmp=imagecreatetruecolor($newwidth,$newheight);


imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);

// Writing the resized image in the ./thumbs subdirectory.

$filename = "./thumbs/$picfile";
imagejpeg($tmp,$filename,100);


imagedestroy($src);
imagedestroy($tmp);



// RESIZING PIC TO 700 px WIDE

$uploadedfile = $_FILES['file']['tmp_name'];

if($ext=="gif"){$src = imagecreatefromgif($uploadedfile);}
if($ext=="jpg"){$src = imagecreatefromjpeg($uploadedfile);}
if($ext=="png"){$src = imagecreatefrompng($uploadedfile);}


list($width,$height)=getimagesize($uploadedfile);

// Setting the picture to be 700 pixels wide,

$newwidth=700;
$newheight=($height/$width)*700;
$tmp=imagecreatetruecolor($newwidth,$newheight);

imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);

// Writing the resized image in the ./pics subdirectory.

$filename = "./pics/$picfile";
imagejpeg($tmp,$filename,100);

imagedestroy($src);
imagedestroy($tmp);
}
?>




Page generated in 0.590034 seconds
Thu, 20 Nov 2008 [10:51] Server Time
Script Created by Conleb.com