Loop only seems to run once

Thanks for bearing with me on this…
Changed the code

function createThumbs( $pathToImages, $pathToThumbs, $thumbWidth )
{
// open the directory
$dir = opendir( $pathToImages );

// loop through it, looking for any/all files:
foreach (glob($pathToImages.“/*.{jpg,jpeg,gif,png,bmp}”, GLOB_BRACE) AS $image) {
$type = exif_imagetype($image); // if you don’t have exif you could use getImageSize()
$allowedTypes = array(
1, // gif
2, // jpg
3, // png
6 // bmp
);
if (!in_array($type, $allowedTypes)) {
continue;
}
switch ($type) {
case 1 :
$im = imagecreatefromgif($image);
$fun = “imagegif”;
break;
case 2 :
$im = imagecreatefromjpeg($image);
$fun = “imagejpeg”;
break;
case 3 :
$im = imagecreatefrompng($image);
$fun = “imagepng”;
break;
case 6 :
$im = imagecreatefromwbmp($image);
$fun = “imagewbmp”;
break;
}
$width = imagesx( $im );
$height = imagesy( $im );

//find name of new image
$new_image = $pathToThumbs.basename($image);
//echo $image." : ".$new_image;

// 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,$im, 0, 0, 0, 0, $new_width, $new_height, $width, $height );

// save thumbnail into a file
$fun( $tmp_img, $new_image );
echo "Dest:".$tmp_img.": Src:".$im;
echo '<div class="thumbnail with-caption">';
echo '<img src="'.$new_image.'" class="img-rounded">';
echo '</div>'; 
echo "\n";
}
// close the directory
closedir( $dir );
}

the result


I didn’t get an error this time, but why the black boxes?