Connecting Tech Pros Worldwide Forums | Help | Site Map

Transparent GIF

Trevor
Guest
 
Posts: n/a
#1: Dec 22 '05
This code is used to resize and then copy a GIF. How do I make it
preserve transparency info?

elseif ($_FILES['imagefile']['type'] == "image/gif") {
list($width, $height, $type, $attr) =
getimagesize($_FILES['imagefile']['tmp_name']);

if ($width >= $height) {
if ($width > 200) {
$ratio = 200/$width;
$image_p = imagecreatetruecolor(200, $height*$ratio);
$image = imagecreatefromgif($_FILES['imagefile']['tmp_name']);
$newimage = imagecopyresampled($image_p, $image, 0, 0, 0, 0, 200,
$height*$ratio, $width, $height);
imagepng($image_p, "image.png");
$image = "image.png";
} else {
copy ($_FILES['imagefile']['tmp_name'], "image.gif");
$image = "image.gif";
}
} else {
if ($height > 134) {
$ratio = 134/$height;
$image_p = imagecreatetruecolor($width*$ratio, 134);
$image = imagecreatefromgif($_FILES['imagefile']['tmp_name']);
$newimage = imagecopyresampled($image_p, $image, 0, 0, 0, 0,
$width*$ratio, 134, $width, $height);
imagepng($image_p, "image.png");
$image = "image.png";
} else {
copy ($_FILES['imagefile']['tmp_name'], "image.gif");
$image = "image.gif";
}


Fred Forsyth
Guest
 
Posts: n/a
#2: Dec 23 '05

re: Transparent GIF


I suspect you need to use "n = ImageColorTransparent($image)" to read
the colour used in the old image, and then
"ImageColorTransparent($image_p, n)" to set in the new one. I've not
checked it myself.

Hope that helps
Fred.

Trevor
Guest
 
Posts: n/a
#3: Dec 23 '05

re: Transparent GIF


$image = imagecreatefromgif($_FILES['imagefile']['tmp_name']);

Will $image retain transparency info in the code above?

Closed Thread