<?php session_start(); ob_start();
$img_size='uploadimages/'.$_FILES['image_orig']['name'];
move_uploaded_file($_FILES['image_orig']['tmp_name'],$img_size);
reduce_image($img_size,$_POST['resize_wid'],$img_size);
function reduce_image($file,$size,$file_path)
{
$image_type=array('gif'=>1,'jpg'=>2,'png'=>3,'bmp'=>6);
$uploadedfile = $file;
list($width,$height,$type)=getimagesize($uploadedfile);
if($width>$size)
{
switch($type)
{
case $image_type['gif']: $src = imagecreatefromgif($uploadedfile); break;
case $image_type['jpg']: $src = imagecreatefromjpeg($uploadedfile); break;
case $image_type['png']: $src = imagecreatefrompng($uploadedfile); break;
//case $image_type['bmp']: $src = imagecreatefromwbmp($uploadedfile); break;
}
// For our purposes, I have resized the image to be 600 pixels wide, and maintain the original aspect
// ratio. This prevents the image from being "stretched" or "squashed". If you prefer some max width other than
// 600, simply change the $newwidth variable
$newwidth=$size;
$newheight=($height/$width)*$size;
$tmp=imagecreatetruecolor($newwidth,$newheight);
// this line actually does the image resizing, copying from the original image into the $tmp image
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
// now write the resized image to disk. I have assumed that you want the
// resized, uploaded image file to reside in the ./images subdirectory.
//$file_path = "uploadimages/".date('Y-d-s').$_FILES[$file]['name'];
switch($type)
{
case $image_type['gif']: $ret=imagegif($tmp,$file_path,100); break;
case $image_type['jpg']: $ret=imagejpeg($tmp,$file_path,100); break;
case $image_type['png']: $ret=imagepng($tmp,$file_path); break;
//case $image_type['bmp']: imagewbmp($tmp,$file_path); break;
}
$_SESSION['succ']=1;
imagedestroy($src);
imagedestroy($tmp);
}
else {
// $ret=move_uploaded_file($uploadedfile,$file_path);
$_SESSION['succ']=0;
}
return $ret;
}
header("Location: image_resize.php");
?>