Connecting Tech Pros Worldwide Help | Site Map

Transparent GIF

  #1  
Old December 22nd, 2005, 11:25 PM
Trevor
Guest
 
Posts: n/a
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";
}

  #2  
Old December 23rd, 2005, 11:25 AM
Fred Forsyth
Guest
 
Posts: n/a

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.

  #3  
Old December 23rd, 2005, 05:45 PM
Trevor
Guest
 
Posts: n/a

re: Transparent GIF


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

Will $image retain transparency info in the code above?

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Noway to create a transparent gif with gdi ! WT answers 5 May 21st, 2007 09:55 AM
System.Drawing.Image.Save() on Transparent GIF Dale answers 4 October 23rd, 2006 05:55 AM
Transparent GIF in a transparent container. Easy right?!?!?! Mark Deibert answers 5 November 20th, 2005 06:38 AM
How to draw a transparent gif in web Minhua Fu answers 1 November 18th, 2005 02:16 AM
Transparent gif screws up display. Jim answers 5 July 21st, 2005 12:32 AM