function resize($cur_dir, $cur_file, $newwidth, $output_dir) {
$dir_name = $cur_dir;
$filename = $cur_file;
$format='';
{
$format = 'image/jpeg';
}
{
$format = 'image/gif';
}
{
$format = 'image/png';
}
if($format!='')
{
$newheight=$height*$newwidth/$width;
switch($format)
{
case 'image/jpeg':
$source = imagecreatefromjpeg($filename);
break;
case 'image/gif';
$source = imagecreatefromgif($filename);
break;
case 'image/png':
$source = imagecreatefrompng($filename);
break;
}
$thumb = imagecreatetruecolor($newwidth,$newheight);
imagealphablending($thumb, false);
$source = @imagecreatefromjpeg("$filename");
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
$filename="$output_dir/$filename";
@imagejpeg($thumb, $filename);
}
}
//call this function using
resize("./input folder", "picture_file_name", "width", "./output folder");