Lasse Madsen wrote:
> Findes der en funktion i PHP, der kan få et billede til at vise
> sig som thumbnail???
>
> Hvis der er, hvordan ser den funktion så ud???
>
Jeg benytter koden nedenfor, der danner dels en reduceret størrelse,
originalstørrelsen og en thumbnail udfra en posted jpg fil.
Mvh. Nikol
$thumbsdir = '/thumbsdir/';
$fpdir='/fpfiles/';
$uploaddir = '/updir/';
$fname=$_FILES['userfile']['name'];
$thumbfile = $thumbsdir . $fname;
$uploadfile = $uploaddir . $fname;
$fpfile = $fpdir . $fname;
$url_refr=$_SERVER["PHP_SELF"];
$url_refr=$url_refr;
inet_auth($url_refr);
if ($_FILES['userfile']['size']>1000000){
echo "The file must be below 1 Mb";
echo $_FILES['userfile']['type'];
exit();
}
else {
if (ereg("^(image/pjpeg)$|^(image/jpeg)$", $_FILES['userfile']['type'])){
if (move_uploaded_file($_FILES['userfile']['tmp_name'],
$uploadfile)) {
//------Opretter thumbnail
define(thumb_width, "100");
$thsource = imagecreatefromjpeg($uploadfile);
$thumbX = thumb_width;
$imageX = imagesx($thsource);
$imageY = imagesy($thsource);
$thumbY = (int)(($thumbX*$imageY) / $imageX );
$dest = imagecreatetruecolor($thumbX, $thumbY);
imagecopyresampled ($dest, $thsource, 0, 0, 0, 0, $thumbX,
$thumbY, $imageX, $imageY);
imagejpeg($dest,$thumbfile);
imagedestroy($dest);
imagedestroy($thsource);
//Opretter størrelse tilpasset index siden
define(fp_width, "420");
$source = imagecreatefromjpeg($uploadfile);
$fpX = fp_width;
$imageX = imagesx($source);
$imageY = imagesy($source);
$fpY = (int)(($fpX*$imageY) / $imageX );
$dest = imagecreatetruecolor($fpX, $fpY);
imagecopyresampled ($dest, $source, 0, 0, 0, 0, $fpX, $fpY,
$imageX, $imageY);
imagejpeg($dest,$fpfile);
imagedestroy($dest);
imagedestroy($source);
//------
//redirect'er tilbage til index side
header("Location: index.php");
} else {
print "<p>Problem handling your file! Here's some debugging
info:\n";
print_r($_FILES);
exit();
}
} else {
echo "The file must be a 'Jpg' file <br /> You tried to upload "
..$_FILES['userfile']['type'];
exit();
}
}
|