Hi, I want to make thumbnails of pictures in a folder with php. I found a script on the internet that kind of worked, but I have some questions. First of all (I'm kind of new to PHP so,) could someone explain this code block?
function dirToArray ($browsedir, $extensions) {
$MAXDIRSIZE = 200;
$nextensions = sizeof ($extensions);
$idirectory = 0;
$directory = dir ($browsedir);
while ($entry = $directory->read()) {
for ($i=1; $i<=$nextensions; $i++) {
$compare = stristr ($entry, $extensions[$i]);
if (strlen($compare) == strlen($extensions[$i])) {
$adirectory[++$idirectory] = $entry;
break;
}
}
}
$directory->close();
return $adirectory;
}
especcially the "$directory->read()" thing, because I just cant find any "read()" function in the php reference. So what is that?
and my second issue is: how can I make actual thumbnails of the pictures? The script I found just resized them to the proper size(which means the picture will have the same filesize and it will take just as long time to Download it as the original), but cant you do so that the picture really gets that small? Or do you have to save the pictures then? I've seen some places that you can make pictures on the fly by using header() and something there, but that wont work on a page with more content would it?check out the GD library for PHP - this is an awesome library for image generation:
<!-- m --><a class="postlink" href="http://www.php.net/gd">http://www.php.net/gd</a><!-- m -->
The "$directory->read()" part of your script looks like it is calling a class. Are you sure this script doesn't assume that you have GD installed already?if you used John Coggeshall scripts from:
<!-- m --><a class="postlink" href="http://www.zend.com/zend/spotlight/photogallery-part2.php">http://www.zend.com/zend/spotlight/phot ... -part2.php</a><!-- m -->
and
<!-- m --><a class="postlink" href="http://www.zend.com/zend/spotlight/photogallery-part1.php">http://www.zend.com/zend/spotlight/phot ... -part1.php</a><!-- m -->
then this uses classes.
I suggest using some of the GD functions if you are new to PHP and then go onto Johns stuff when you are a bit more experienced.
There is a great beginners GD tutorial here:
<!-- m --><a class="postlink" href="http://hotwired.lycos.com/webmonkey/01/21/index4a.html?tw=programming">http://hotwired.lycos.com/webmonkey/01/ ... rogramming</a><!-- m -->
HTH
function dirToArray ($browsedir, $extensions) {
$MAXDIRSIZE = 200;
$nextensions = sizeof ($extensions);
$idirectory = 0;
$directory = dir ($browsedir);
while ($entry = $directory->read()) {
for ($i=1; $i<=$nextensions; $i++) {
$compare = stristr ($entry, $extensions[$i]);
if (strlen($compare) == strlen($extensions[$i])) {
$adirectory[++$idirectory] = $entry;
break;
}
}
}
$directory->close();
return $adirectory;
}
especcially the "$directory->read()" thing, because I just cant find any "read()" function in the php reference. So what is that?
and my second issue is: how can I make actual thumbnails of the pictures? The script I found just resized them to the proper size(which means the picture will have the same filesize and it will take just as long time to Download it as the original), but cant you do so that the picture really gets that small? Or do you have to save the pictures then? I've seen some places that you can make pictures on the fly by using header() and something there, but that wont work on a page with more content would it?check out the GD library for PHP - this is an awesome library for image generation:
<!-- m --><a class="postlink" href="http://www.php.net/gd">http://www.php.net/gd</a><!-- m -->
The "$directory->read()" part of your script looks like it is calling a class. Are you sure this script doesn't assume that you have GD installed already?if you used John Coggeshall scripts from:
<!-- m --><a class="postlink" href="http://www.zend.com/zend/spotlight/photogallery-part2.php">http://www.zend.com/zend/spotlight/phot ... -part2.php</a><!-- m -->
and
<!-- m --><a class="postlink" href="http://www.zend.com/zend/spotlight/photogallery-part1.php">http://www.zend.com/zend/spotlight/phot ... -part1.php</a><!-- m -->
then this uses classes.
I suggest using some of the GD functions if you are new to PHP and then go onto Johns stuff when you are a bit more experienced.
There is a great beginners GD tutorial here:
<!-- m --><a class="postlink" href="http://hotwired.lycos.com/webmonkey/01/21/index4a.html?tw=programming">http://hotwired.lycos.com/webmonkey/01/ ... rogramming</a><!-- m -->
HTH