<?php  include('SimpleImage.php');
$dirMenu = 'imagesh';

if (file_exists($dirMenu)) {
	recurseDir($dirMenu); 
}

function recurseDir($dir){
	$all = "";
	if(is_dir($dir)){
		if($dh = opendir($dir)){
			while(($file = readdir($dh)) != false){
				if($file != '.' && $file != '..' && $file != 'Thumbs.db' && $file != 'thumbs.db' ){
					 if(!is_dir($dir . $file)){
							$all .= $file .",";
						}
				}
			}
			$all =substr($all,0,strlen($all)-1);
			resizeImages($all,$dir);
		}
		closedir($dh);         
	}
}
function resizeImages($all,$dir){
$width = 50;
$height = 50;
$newdir = $dir."1";
if (!file_exists($newdir)) {
	mkdir($newdir,0777); 
}

	$aryFile = explode(",",$all);
	$image = new SimpleImage();
	for($i = 0 ; $i< count($aryFile); $i++)
	{
		$src_dims = getimagesize($dir."/".$aryFile[$i]);
		 $image_type = $src_dims[2];
      	if( $image_type == IMAGETYPE_JPEG ) {
         $image = imagecreatefromjpeg($dir."/".$aryFile[$i]);
		 $new_image = imagecreatetruecolor($width, $height);

      imagecopyresampled($new_image, $image, 0, 0, 0, 0, $width, $height, $src_dims[0],$src_dims[1]);
		 imagejpeg($new_image,$newdir."/".'n'.$aryFile[$i],$compression = 75);
      }
	}
}
	
    
?>