A small imagecopyresampled issue

by using the following script i get this error message:


Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 10432 bytes) 


function createthumb($name,$filename)
{
$system=explode(".",$name);
if (preg_match("/jpg|jpeg/",$system[1])){$src_img=imagecreatefromjpeg($name);}
if (preg_match("/png/",$system[1])){$src_img=imagecreatefrompng($name);}
$old_x=imageSX($src_img);
$old_y=imageSY($src_img);
 
$thumb_w=150;
$thumb_h=150;
 
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); 
if (preg_match("/png/",$system[1]))
{
imagepng($dst_img,$filename); 
} else {
imagejpeg($dst_img,$filename); 
}
imagedestroy($dst_img); 
imagedestroy($src_img); 
}

It happens when the images are bigger than 3Mpixels