Hi,
Just wondering if anyone can help me out here.
I have a function which I use to resize uploaded images, script works fine for the most part.
However when I use this with a transparent gif the image isnt sampled properly and the transparency turns black.
I have been messing about using the various image functions in php but im not gettign anywhere. Could anyone suggest what needs to be added to the funtion to handle transparent gifs.
Thanks
[code=php]
function resize($file,$path,$ext,$size)
{
list($owidth, $oheight) = getimagesize($_FILES[$file][‘tmp_name’]);
$nwidth = $size;
$nheight = $nwidth / $owidth * $oheight;
$resized = imagecreatetruecolor($nwidth, $nheight);
if($ext == ‘png’)
{$original = imagecreatefrompng($_FILES[$file][‘tmp_name’]);}
if($ext == ‘jpg’ || $ext == ‘jpeg’)
{$original = imagecreatefromjpeg($_FILES[$file][‘tmp_name’]);}
if($ext == ‘gif’)
{$original = imagecreatefromgif($_FILES[$file][‘tmp_name’]);}
imagecopyresampled($resized, $original, 0, 0, 0, 0, $nwidth, $nheight, $owidth, $oheight);
if($ext == ‘png’){
imagepng($resized,$path);}
if($ext == ‘jpg’ || $ext == ‘jpeg’)
{imagejpeg($resized,$path);}
if($ext == ‘gif’)
{imagegif($resized,$path);}
}