I need to create thumbnails for all the jpg images in a folder. When I compile it, the error message pops out:
Parse error: syntax error, unexpected T_VARIABLE in /volume1/web/CAL1/thumb.php on line 6
and here is my code:
<?php
$pathToImages = "./images/";
$pathToThumbs = "./images/thumbnails/";
$thumbWidth = 110;
$dir = opendir($pathToImages);
while (false != ($fname = readdir($dir))) {
$info = pathinfo($pathToImages . $fname);
if ( strtolower($info['extension']) == 'jpg' ) {
echo "Creating thumbnail for {$fname} <br />";
$img = imagecreatefromjpeg( "{$pathToImages}{$fname}" );
$width = imagesx( $img );
$height = imagesy( $img );
$new_width = $thumbWidth;
$new_height = floor( $height * ( $thumbWidth / $width ) );
$tmp_img = imagecreatetruecolor( $new_width, $new_height );
imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
imagejpeg( $tmp_img, "{$pathToThumbs}{$fname}" );
}
}
closedir( $dir );
?>
I cannot find where does the error come from. Can anyone help me please? thanks in advance.