red-x Posted December 22, 2008 Share Posted December 22, 2008 Hi, I got this code from a website to upload images and create thumbnails. It works great with png and jpg images but with gif (The ones that move) images it uploads the image good and everything but when it creates the thumbnail the image stops moving. Like if its only using the first layer of the image to create the thumbnail. I'm not sure if you guys know what I mean so here are the images.. and the thumbnail.. lol Is there away to make it smaller but keep the animation? The Code.. <?php $idir = "avatars/"; // Path To Images Directory $tdir = "avatars/thumbs/"; // Path To Thumbnails Directory $twidth = "80"; // Maximum Width For Thumbnail Images $theight = "80"; // Maximum Height For Thumbnail Images if (!isset($_GET['subpage'])) { // Image Upload Form Below ?> <form method="post" action="test.php?subpage=upload" enctype="multipart/form-data"> File:<br /> <input type="file" name="imagefile" id="imagefile" class="form"> <br /><br /> <input name="submit" type="submit" value="Sumbit" class="form"> <input type="reset" value="Clear" class="form"> </form> <?php } else if (isset($_GET['subpage']) && $_GET['subpage'] == 'upload') { // Uploading/Resizing Script $url = $_FILES['imagefile']['name']; // Set $url To Equal The Filename For Later Use $info = getimagesize($_FILES['imagefile']['tmp_name']); switch ($info[2]) { case IMAGETYPE_GIF: $simg = imagecreatefromgif($_FILES['imagefile']['tmp_name']); $ext = '.gif'; break; case IMAGETYPE_JPEG: $simg = imagecreatefromjpeg($_FILES['imagefile']['tmp_name']); $ext = '.jpg'; break; case IMAGETYPE_PNG: $simg = imagecreatefrompng($_FILES['imagefile']['tmp_name']); $ext = '.png'; break; default: $simg = false; } if ($simg) { $file_name = substr($_FILES['imagefile']['name'], 0, -strlen(strrchr($_FILES['imagefile']['name'], '.'))); $copy = move_uploaded_file($_FILES['imagefile']['tmp_name'], $idir . $file_name . $ext); // Move Image From Temporary Location To Permanent Location if ($copy) { // If The Script Was Able To Copy The Image To It's Permanent Location print 'Image uploaded successfully.<br />'; // Was Able To Successfully Upload Image $currwidth = imagesx($simg); // Current Image Width $currheight = imagesy($simg); // Current Image Height if ($currheight > $currwidth) { // If Height Is Greater Than Width $zoom = $twidth / $currheight; // Length Ratio For Width $newheight = $theight; // Height Is Equal To Max Height $newwidth = $currwidth * $zoom; // Creates The New Width } else { // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height) $zoom = $twidth / $currwidth; // Length Ratio For Height $newwidth = $twidth; // Width Is Equal To Max Width $newheight = $currheight * $zoom; // Creates The New Height } $dimg = imagecreate($newwidth, $newheight); // Make New Image For Thumbnail imagetruecolortopalette($simg, false, 256); // Create New Color Pallete $palsize = ImageColorsTotal($simg); for ($i = 0; $i < $palsize; $i++) { // Counting Colors In The Image $colors = ImageColorsForIndex($simg, $i); // Number Of Colors Used ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']); // Tell The Server What Colors This Image Will Use } imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight); // Copy Resized Image To The New Image (So We Can Save It) switch ($info[2]) { case IMAGETYPE_GIF: imagegif($dimg, $tdir . $file_name . $ext); break; case IMAGETYPE_JPEG: imagejpeg($dimg, $tdir . $file_name . $ext); break; case IMAGETYPE_PNG: imagepng($dimg, $tdir . $file_name . $ext); break; } imagedestroy($simg); // Destroying The Temporary Image imagedestroy($dimg); // Destroying The Other Temporary Image print 'Image thumbnail created successfully.'; // Resize successful } else { print '<font color="#FF0000">ERROR: Unable to upload image.</font>'; // Error Message If Upload Failed } } else { print '<font color="#FF0000">ERROR: Wrong filetype (has to be a .jpg, .jpeg, .gif, or .png. Yours is '; // Error Message If Filetype Is Wrong print strrchr($_FILEs['imagefile']['name'], '.'); // Show The Invalid File's Extention print '.</font>'; } } ?> Thank you in advance. Link to comment https://forums.phpfreaks.com/topic/137988-gif-image-upload-problem/ Share on other sites More sharing options...
genericnumber1 Posted December 22, 2008 Share Posted December 22, 2008 http://letmegooglethatforyou.com/?q=animated+gif+manipulation+php Link to comment https://forums.phpfreaks.com/topic/137988-gif-image-upload-problem/#findComment-721186 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.