note 43637 deleted from function.imagecreatefromgif by tomsommer

From: Date: Mon, 28 Jun 2004 22:09:54 +0000
Subject: note 43637 deleted from function.imagecreatefromgif by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-72076@lists.php.net to get a copy of this message
Note Submitter: Randolpho ---- Ok, here's an interesting tidbit. I wouldn't call it a bug, exactly, but it did make for an interesting workaround the GD/GIF situation. using PHP Version 4.3.4/GD bundled (2.0.15 compatible), I am able to use imagecreatefromgif() to load an image into GD, although I am not able to use imagegif() to display it. I'm not sure *why* this is, but the practical aspect is that if you need to do dynamic changes to a loaded image and want to display it to the browser (for example, a dynamic thumbnailer), you can load a gif image using imagecreatefromgif(), and then display it using a different image type! I recommend using PNG, since JPG is a lossy format. For example, given some image at $location: <?php $test = strtolower($location); if(strpos($test, ".jpg") !== false || strpos($test, ".jpeg") !== false) { $this->OriginalImage = imagecreatefromjpeg($location); $ImageType = "jpg"; header("Content-type: image/jpeg"); } // transform GIFs into PNGs else if(strpos($test, ".gif") !== false) { $OriginalImage = imagecreatefromgif($location); $ImageType = "png"; header("Content-type: image/png"); } else if(strpos($test, ".png") !== false) { $OriginalImage = imagecreatefrompng($location); $ImageType = "png"; header("Content-type: image/png"); } /* * * Do some image manipulation, stored for this example as $OutputImage * */ switch ($ImageType) { case "jpg": imagejpeg($OutputImage); break; case "png": imagepng($OutputImage); break; default: break; } ?> Now, as I said, I'm not sure if this is an oversight/bug or not, but if you can get it working, it's a great workaround for GD's lack of GIF processing.

« previous php.notes (#72076) next »