Thread: image work
View Single Post
Old 12-13-2004, 06:18 PM   #3 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,505
sde is on a distinguished road
this is a function i wrote to upload an image, create a thumb with a height of 80 and resizes the width proportionately. it upload the image and names the thumb with a _t at the end. hope this helps.

$filename would be the temporary file name ( $_FILES['somefile']['tmp_name'] )
$name would be what you want it to be named
PHP Code:
<?
function getRootPath(){
  return 
"/home/user/public_html/";
}

function 
uploadPhoto($filename,$name){
  
$name stripslashes($name);
  list(
$width$height) = getimagesize($filename);
  
  
$percent 80 $height;
  
  
$new_width $width $percent;
  
$new_height $height $percent;
  
  
// Resample
  
$image_p imagecreatetruecolor($new_width$new_height);
  
$image imagecreatefromjpeg($filename);
  
imagecopyresampled($image_p$image0000$new_width$new_height$width$height);
  
  
$newfile getRootPath()."images/photos/".$name;
  
move_uploaded_file($filename,$newfile);
  
chmod($newfile0644);
  
  
$array explode(".",$name);
  
imagejpeg($image_pgetRootPath()."images/photos/".$array[0]."_t.".$array[1]);
}
?>
__________________
Mike
sde is offline   Reply With Quote