Den her laber thumbnails af alle billeder i en mappe til en anden mappe (hvis ikke de ikke allerede er lavet)
du kan evt. køre det her efter at filen er upload'et
<?
$thumb = "./updir/thumbnail/";
$img = "./updir/";
function resize ($sourcefile, $dest_x, $dest_y, $targetfile, $jpegqual, $extension)
{
/* Get the dimensions of the source picture */
$picsize=getimagesize("$sourcefile");
$source_x = $picsize[0];
$source_y = $picsize[1];
// Billedet bliver hentet
if ($extension == ".jpg"){
$source_id = imageCreateFromJPEG("$sourcefile");
}elseif($extension == ".png"){
$source_id = imageCreateFromPNG("$sourcefile");
}elseif($extension == ".gif"){
// $source_id = imageCreateFromGIF("$sourcefile"); Har ikke prøvet med GIF
return;
}
// Laver nyt billede
$target_id=imagecreatetruecolor($dest_x, $dest_y);
// Kopiere det org. store ind i det lille nye
$target_pic=imagecopyresampled($target_id,$source_id,
0,0,0,0,
$dest_x,$dest_y,
$source_x,$source_y);
/* Create a jpeg with the quality of "$jpegqual" out of the
image object "$target_pic".
This will be saved as $targetfile */
if ($extension == ".jpg"){
imagejpeg ($target_id,"$targetfile",$jpegqual);
}elseif($extension == ".png"){
imagepng ($target_id,"$targetfile");
// }elseif($extension == ".gif"){ GIF virker ikke på 1go lige nu!
// imagegif($target_id,$targetfile);
}
return true;
}
echo"<CENTER>";
$libery="updir/";
$handle=opendir($libery); //opens directory
while($file=readdir($handle)){ // reads the directory
$extension=substr($file,-4); // gets the extension of the files
if(($extension == ".jpg") || ($extension == ".gif") || ($extension == ".png") ){ // checks for image files
$thumbplace = "$thumb"."$file";
$fileplace = "$img"."$file";
if (!file_exists($thumbplace))
{
list($width, $height, $type, $attr) = getimagesize("$fileplace");
if ($width > $height){
$h = $height / $width * 200;
$w = 200;
}else{
$w = $width / $height * 200;
$h = 200;
}
$vises = resize("$fileplace", "$w", "$h", "$thumbplace", "100", "$extension");
}else{
$vises = "1";
}
/* Skal kun bruges hvis de skal vises */
if ($vises){
echo"<center>$file";
echo"<center><a href='Http://www.dinside.dk/updir/$file' target='_blank'><img src='$thumbplace' border='0'></a><BR>"; // <------ ÆNDRE DEN
}
/* */
}
}
?>