Create thumbnails of all the images in a directory

This example reads a directory and creats thumbnails of all the images. It can be modified to only read certain files, the files can or can not be overwriten, the filenames can be changed and the ImageMagick code can be modified to add watermarks etc.

The file names will be the same type as the original with a thumb_ prefix

// Setup the maximium width and height for the finished image
$max_width "200";
$max_height "90";

// Directory containing the images
$dir 'photos'

// Select all jpg, png and gif images
foreach (glob($dir."{*.jpg,*.png,*.gif}",GLOB_BRACE ) as $filename) {

// Get the image size for use in the code
$size=GetImageSize$filename );

$new_name "thumb_".$filename;

$cmd $filename -thumbnail $max_widthx$max_height ";
exec("convert $cmd $new_name");