I have a directory of images.
I tried to create thumbnails of each image, but with this, only 1 seems to get produced.
<?php
$providerID = $_GET['providerID'];
function createThumbs( $pathToImages, $pathToThumbs, $thumbWidth )
{
// open the directory
$dir = opendir( $pathToImages );
// loop through it, looking for any/all files:
while (false !== ($fname = readdir( $dir ))) {
// parse path for the extension
$info = pathinfo($pathToImages . $fname);
// continue only if this is a image
if ( strtolower($info['extension']) == 'jpg' || strtolower($info['extension']) == 'jpeg' || strtolower($info['extension']) == 'png' || strtolower($info['extension']) == 'gif')
{
//echo "Creating thumbnail for {$fname} <br />";
// load image and get image size
$img = imagecreatefromjpeg( "{$pathToImages}{$fname}" );
$width = imagesx( $img );
$height = imagesy( $img );
// calculate thumbnail size
$new_width = $thumbWidth;
$new_height = floor( $height * ( $thumbWidth / $width ) );
// create a new temporary image
$tmp_img = imagecreatetruecolor( $new_width, $new_height );
// copy and resize old image into new image
imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
// save thumbnail into a file
imagejpeg( $tmp_img, "{$pathToThumbs}{$fname}" );
echo '<div class="thumbnail with-caption">';
echo '<img src="'.$pathToThumbs.$fname.'" class="img-rounded">';
echo '</div>';
}
// close the directory
closedir( $dir );
}
}
createThumbs("../providers/{$providerID}/","../providers/{$providerID}/thumbs/",200);
?>
I thought since I have it in the if loop they would all get made?
How can I make it go through every image?