I think I figured it out, and since I couldn't find a solution anywhere else, I figured I'd post what I found out here for anyone else who needs help with this.
Basically, for GIF images, in order to preserve the transparency in the new resized image, you can't use a true color image as a destination. You need to create a regular palette image as the destination image and designate the first color as transparent.
$info = getimagesize( $file );
//-----------------
// create the image
//-----------------
switch ( $info[2] ) // which type of image is it?
{
case 1: $im_org = imageCreateFromGIF( $file ); break;
case 2: $im_org = imageCreateFromJPEG( $file ); break;
case 3: $im_org = imageCreateFromPNG( $file ); break;
}
//-----------------
// resize the image
//-----------------
if ( $info[2] == 1 ) // create a palette image for GIFs
{
$im_new = imageCreate( $newWidth, $newHeight );
$transparent = imagecolorallocatealpha( $im_new, 255, 255, 255, 127 );
imagecolortransparent( $im_new, $transparent );
}
else // create a true color image for PNGs and JPEGs
{
$im_new = imageCreateTrueColor( $newWidth, $newHeight );
}
if ( $info[2] == 3 ) // alphablending OFF and savealpha ON for PNGs
{
imagealphablending( $im_new, FALSE );
imagesavealpha( $im_new, TRUE );
}
imageCopyResampled( $im_new, $im_org, 0, 0, 0, 0, $newWidth, $newHeight, $info[0], $info[1]);
//------------------------------
// send the image to the browser
//------------------------------
switch ( $info[2] )
{
case 1:
{
@header("Content-type: image/gif");
imageGIF( $im_new );
break;
}
case 2:
{
@header("Content-type: image/jpeg");
imageJPEG( $im_new );
break;
}
case 3:
{
@header("Content-type: image/png");
imagePNG( $im_new );
break;
}
}
imageDestroy( $im_org );
imageDestroy( $im_new );