<?php header('Content-type: image/jpeg');

// The file
$filename = 'test.jpg';
$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);         
	}
}

// Set a maximum height and width


// Content type
function resizeImages($all,$dir){
	$aryFile = explode(",",$all);
	for($i = 0 ; $i< count($aryFile); $i++)
	{
	$width = 20;
$height = 20;
		$filename = $aryFile[$i];
		// Get new dimensions
		list($width_orig, $height_orig) = getimagesize($filename);
		
		$ratio_orig = $width_orig/$height_orig;
		
		if ($width/$height > $ratio_orig) {
		   $width = $height*$ratio_orig;
		} else {
		   $height = $width/$ratio_orig;
		}
		
		// Resample
		$image_p = imagecreatetruecolor($width, $height);
		$image = imagecreatefromjpeg($filename);
		imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
/*		 Output
		imagejpeg($image_p, null, 100);*/

	}
}

?>
