I'm trying to resize an image on the fly, but if the image contains transparency, it isn't preserved. I'm a bit confused by all the various alpha related GD functions. Here's what I have. I'm sure I need to add something around the imageCopyResampled part.
$info = getimagesize( $file );
//-----------------
// create the image
//-----------------
switch ( $info[2] )
{
case 1: $im_org = imageCreateFromGIF( $file ); break;
case 2: $im_org = imageCreateFromJPEG( $file ); break;
case 3: $im_org = imageCreateFromPNG( $file ); break;
}
//--------------------------------
// do we have to resize the image?
//--------------------------------
if ( $info[0] > $maxWidth )
{
$width = $maxWidth;
$height = round( ( $width / $info[0] ) * $info[1] );
$im_new = imageCreateTrueColor( $width, $height );
imageCopyResampled( $im_new, $im_org, 0, 0, 0, 0, $width, $height, $info[0], $info[1]);
}
else
{
$im_new = $im_org;
}
//------------------------------
// send the image to the browser
//------------------------------
switch ( $info[2] )
{
case 1:
{
@header("Content-type: image/gif");
imageTrueColorToPalette( $im_new, TRUE, 256 );
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 );