Nu ser min kode sådan her ud, efter jeg fandt din i GUIDES.
Men jeg kan stadig ikke få den til og vise bmp. Og heller ikke resize til 150x150.
<?php
echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Strict //EN\" \"
http://www.w3.org/TR/html4/strict.dtd\">\n";echo "<html>\n";
echo "<head>\n";
echo "<title>Min test</title>\n";
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\">\n";
echo "</head>\n";
echo "<body>\n";
echo "<div id=\"content\">\n";
echo "<h1>Her er der billeder</h1>\n";
function resize( $filename, $newfilename, $maxw, $maxh, $quality=85 )
{
$ext = strtolower( pathinfo( $filename, PATHINFO_EXTENSION ) );
switch($ext)
{
case 'jpeg':
case 'jpe':
case 'jpg':
$srcim = imagecreatefromjpeg( $filename );
break;
case 'gif':
$srcim = imagecreatefromgif( $filename );
break;
case 'png':
$srcim = imagecreatefrompng( $filename );
break;
case 'bmp':
$srcim = imagecreatefrompng( $filename );
break;
default:
return false;
}
$ow = imagesx( $srcim );
$oh = imagesy( $srcim );
$wscale = $maxw / $ow;
$hscale = $maxh / $oh;
$scale = min( $hscale, $wscale );
$nw = round( $ow * $scale, 0 );
$nh = round( $oh * $scale, 0 );
$dstim = imagecreatetruecolor( $nw, $nh );
imagecopyresampled( $dstim, $srcim, 0, 0, 0, 0, $nw, $nh, $ow, $oh );
switch($ext)
{
case 'jpeg':
case 'jpe':
case 'jpg':
imagejpeg( $dstim, $newfilename, $quality );
break;
case 'gif':
imagegif( $dstim, $newfilename );
break;
case 'png':
$png_q = floor( abs( $quality / 10 - 9.9 ) );
imagepng( $dstim, $newfilename, $png_q );
break;
case 'bmp':
imagegif( $dstim, $newfilename );
break;
default:
return false;
}
imagedestroy( $dstim );
imagedestroy( $srcim );
return file_exists($newfilename);
}
$dir = getcwd();
$allowExt = array("jpg","JPG","bmp","BMP","png","PNG");
// Open a known directory, and proceed to read its contents
if (is_dir($dir)){
if ($dh = opendir($dir)){
$fileArray = array();
while(($file = readdir($dh)) !== false){
$arr = explode (".", $file);
$extension = end($arr);
if(in_array($extension,$allowExt)){
if(file_exists("thumb_" . $file) || preg_match('/^thumb_/', $file)){
;
}else{
resize($file, getcwd() . "/thumb_" . $file, 150, 150);
}
if(!preg_match('/^thumb_/', $file)){
$thumb = "thumb_" . $file;
$fileArray[$thumb] = $file;
}
}
}
closedir($dh);
}
}
if(count($fileArray)>0){
echo "<table id=\"centerTable\">\n";
foreach($fileArray as $thumb => $file){
echo "<tr><td><a target=\"_blank\" href=\"" . $file . "\"><img src=\"".$thumb."\"></a></td></tr>\n";
echo "<tr><td>" . $file . "</td></tr>\n";
}
echo "</table>\n";
}else{
echo "Vi har ikke uploadet nogle billeder endnu, de kommer...";
}
echo "</div>\n";
echo "</body>\n";
echo "</html>\n";
?>