<?php
function ikona($nazwa)
{
if(file_exists("small-$nazwa")) return;
$img1 = imagecreatefromjpeg($nazwa);
$img2 = imagecreatetruecolor(260,190);
$white = imagecolorallocate($img2, 100, 100, 100);
imagefill($img2, 0, 0, $white);
$skalax=250/imagesx($img1);
$skalay=180/imagesy($img1);
$skala=$skalax<$skalay ? $skalax : $skalay;
$sx=round($skala*imagesx($img1));
$sy=round($skala*imagesy($img1));
imagecopyresampled($img2, $img1, round((260-$sx)/2), round((190-$sy)/2), 0, 0, $sx, $sy, imagesx($img1), imagesy($img1));
imagejpeg($img2,"small-$nazwa");
imagedestroy($img2);
imagedestroy($img1);
}
//odczytanie listy plików z katalogu
if ($handle = opendir('./'))
{
/* while (false !== ($file = readdir($handle)))
if(is_file($file) && eregi("\.jp[e]?g$",$file) && !eregi("^small-",$file)) $list[]=$file;
closedir($handle);} */
while (false !== ($file = readdir($handle)))
if(is_file($file) && preg_match('/.+\.(jpeg|jpg|gif)$/',$file) && !preg_match('/small/',$file) ) $list[]=$file;
closedir($handle);
}
foreach($list as $plik)
{
ikona($plik);
print "<img src=\"small-$plik\" border=\"0\" alt=\"$plik\" />";
}
?>
|