<?php
$pathToImages = "images/"; //folder duze zdjecia
$pathToThumbs = "thumbs/"; //folder na miniatury
$thumbWidth = 150; //szerokosc miniatury
$thumbHeight = 0; //wysokosc miniatury, gdy "0" zachowana jest proporcja szerokosc x wysokosc
function createThumbs( $pathToImages, $pathToThumbs, $thumbWidth, $thumbHeight)
{
//otwiera katalog
//szukanie obrazow JPG
while (false !== ($fname = readdir( $dir ))) {
$info = pathinfo($pathToImages . $fname); // dalej idzie gdy rozszezenie JPG
{
echo "Utworzono miniature pliku: {$fname} <br />"; // wczytanie rozmiaru obrazu
$img = imagecreatefromjpeg( "{$pathToImages}{$fname}" );
$width = imagesx( $img );
$height = imagesy( $img );
// obliczanie rozmiaru miniaturki
$new_width = $thumbWidth;
// $new_height = floor( $height * ( $thumbWidth / $width ) );
if ( $thumbHeight == 0 )
{
$new_height = floor( $height * ( $thumbWidth / $width ) ); }
else {
$new_height = $thumbHeight;
}
// tworzenie nowych miniatur
$tmp_img = imagecreatetruecolor( $new_width, $new_height );
// kopiowanie i zmniejszanie starych plikow w nowe
imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
// utworzenie miniatur
imagejpeg( $tmp_img, "{$pathToThumbs}{$fname}" );
}
}
// zamykanie katalogu
}
createThumbs( $pathToImages, $pathToThumbs, $thumbWidth, $thumbHeight);
?>