Hey everybody I have created an image resize function that saves the specific image file to a known path everything works except when I upload a png image… I am not sure why but here the error code and the function in whole…
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 14775384 bytes) in /home/accessan/public_html/animeharvest/membersystem/ini/func.ini.php on line 81
function getImages($path){
//-- make sure it over the 150 mark...
$image = getimagesize($path);
if($image[0]<150 || $image[1]<150 ) {$_SESSION['tmp_path'] = $path; return $path;}else{
$type = explode('.',$path);
$type = array_reverse($type);
list($width,$height) = getimagesize($path);
$modwidth = 150;
$diff = round ($width / $modwidth);
$modheight = round($height / $diff) ;
$name = (isset($_SESSION['member']) && $_SESSION['member']!='guest') ? $_SESSION['member']:rand(0000,9999);
if(isset($_POST['username'])){$name=$_POST['username'];}
// -- find type
if($type[0]=='png'){
if(file_exists('membersystem/images/'.$name.'.png')){$name=rand(0000,9999);}
$tn = imagecreatetruecolor($modwidth, $modheight);
//line 81
$new_im = imagecreatefrompng($path);
// line 81 end.
imagecopyresampled($tn,$new_im,0,0,0,0,$modwidth,$modheight,$width,$height);
imagepng($tn,'membersystem/images/'.$name.'.png');
$path = '/membersystem/images/'.$name.'.png';
$_SESSION['tmp_path'] = $path;
return $path;
}elseif($type[0]=='gif'){
if(file_exists('membersystem/images/'.$name.'.gif')){$name=rand(0000,9999);}
$tn = imagecreatetruecolor($modwidth, $modheight);
$new_im = imagecreatefromgif($path);
imagecopyresampled($tn,$new_im,0,0,0,0,$modwidth,$modheight,$width,$height);
imagegif($tn,'membersystem/images/'.$name.'.gif');
$path = '/membersystem/images/'.$name.'.gif';
$_SESSION['tmp_path'] = $path;
return $path;
}elseif ($type[0]=='jpg' || $type[0]=='jpeg'){
if(file_exists('membersystem/images/'.$name.'.jpeg')){$name=rand(0000,9999);}
$tn = imagecreatetruecolor($modwidth, $modheight);
$new_im = imagecreatefromjpeg($path);
imagecopyresampled($tn,$new_im,0,0,0,0,$modwidth,$modheight,$width,$height);
imagejpeg($tn,'membersystem/images/'.$name.'.jpeg');
$path = '/membersystem/images/'.$name.'.jpeg';
$_SESSION['tmp_path'] = $path;
return $path;
}
}//end else.
}//end getImages function..