I am trying to resize images as per the code below as a user uploads their jpeg. However I run into a memory error each time on the imagecreatefromjpeg line. I can't change the memory size 16M on my host server and would like to enable the users to upload an image of 1.5M as the max. Is there a more efficient way to do this? Thanks

function resampimagejpg( $forcedwidth, $forcedheight, $sourcefile, $destfile )
{

require('4r5690/info.php');

$destfile = $g_imageDir . "/" . $destfile;

$fw = $forcedwidth;
$fh = $forcedheight;
$is = getimagesize( $sourcefile );
if( $is[0] >= $is[1] )
{
$orientation = 0;
}
else
{
$orientation = 1;
$fw = $forcedheight;
$fh = $forcedwidth;
}

if ( $is[0] > $fw || $is[1] > $fh )
{
if( ( $is[0] - $fw ) >= ( $is[1] - $fh ) )
{
$iw = $fw;
$ih = ( $fw / $is[0] ) * $is[1];
}
else
{
$ih = $fh;
$iw = ( $ih / $is[1] ) * $is[0];
}
$t = 1;
}
else
{
$iw = $is[0];
$ih = $is[1];
$t = 2;
}

fopen($destfile,"w");

if ( $t == 1 )
{

$img_src = imagecreatefromjpeg( $sourcefile );
$img_dst = imagecreatetruecolor( $iw, $ih ) or die("Cannot Initialize new GD image stream");

imagecopyresampled( $img_dst, $img_src, 0, 0, 0, 0, $iw, $ih, $is[0], $is[1] );
imagedestroy($img_src);
if( !imagejpeg( $img_dst, $destfile, 90 ) )
{
$img_dst = null;
return false;
}
$img_dst = null;
}
else if ( $t == 2 )
{

copy( $sourcefile, $destfile );
}

return true;

}