diff -Naur Imaging-1.1.6/PIL/GifImagePlugin.py Imaging-1.1.6-sam/PIL/GifImagePlugin.py
--- Imaging-1.1.6/PIL/GifImagePlugin.py	2006-12-03 12:37:16.000000000 +0100
+++ Imaging-1.1.6-sam/PIL/GifImagePlugin.py	2007-07-16 16:27:10.843454500 +0200
@@ -17,6 +17,7 @@
 # 2001-04-17 fl   Added palette optimization (0.7)
 # 2002-06-06 fl   Added transparency support for save (0.8)
 # 2004-02-24 fl   Disable interlacing for small images
+# 2007-07-16 sam  Fixed palette bug and transparency with animation
 #
 # Copyright (c) 1997-2004 by Secret Labs AB
 # Copyright (c) 1995-2004 by Fredrik Lundh
@@ -56,7 +57,7 @@
     format = "GIF"
     format_description = "Compuserve GIF"
 
-    global_palette = None
+    global_palette, currpal = None, None
 
     def data(self):
         s = self.fp.read(1)
@@ -70,7 +71,7 @@
         s = self.fp.read(13)
         if s[:6] not in ["GIF87a", "GIF89a"]:
             raise SyntaxError, "not a GIF file"
-
+            
         self.info["version"] = s[:6]
 
         self.size = i16(s[6:]), i16(s[8:])
@@ -81,6 +82,7 @@
 
         bits = (flags & 7) + 1
 
+        self.info["background"] = 0
         if flags & 128:
             # get global palette
             self.info["background"] = ord(s[11])
@@ -88,8 +90,8 @@
             p = self.fp.read(3<<bits)
             for i in range(0, len(p), 3):
                 if not (chr(i/3) == p[i] == p[i+1] == p[i+2]):
-                    p = ImagePalette.raw("RGB", p)
-                    self.global_palette = self.palette = p
+                    #p = ImagePalette.raw("RGB", p)
+                    self.global_palette = self.currpal = p
                     break
 
         self.__fp = self.fp # FIXME: hack
@@ -123,7 +125,7 @@
             self.im = self.dispose
             self.dispose = None
 
-        self.palette = self.global_palette
+        self.currpal = self.global_palette
 
         while 1:
 
@@ -149,8 +151,11 @@
                         # disposal methods
                         if flags & 8:
                             # replace with background colour
-                            self.dispose = Image.core.fill("P", self.size,
-                                self.info["background"])
+                            if self.info.has_key("transparency"):  # This is how the webbrowsers do it
+                                self.dispose = Image.core.fill("P", self.size, self.info["transparency"])
+                            else:
+                                self.dispose = Image.core.fill("P", self.size, self.info["background"])
+                                
                         elif flags & 16:
                             # replace with previous contents
                             self.dispose = self.im.copy()
@@ -167,6 +172,11 @@
                     pass
 
             elif s == ",":
+                if frame == 0:
+                    if self.info.has_key("transparency"):
+                        self.im = Image.core.fill("P", self.size, self.info["transparency"])
+                    else:
+                        self.im = Image.core.fill("P", self.size, self.info["background"])
                 #
                 # local image
                 #
@@ -181,16 +191,21 @@
 
                 if flags & 128:
                     bits = (flags & 7) + 1
-                    self.palette =\
-                        ImagePalette.raw("RGB", self.fp.read(3<<bits))
+                    self.currpal = self.fp.read(3<<bits)#\
+                        #ImagePalette.raw("RGB", self.fp.read(3<<bits))
+                        
 
                 # image data
+                transparency = -1
+                if self.info.has_key("transparency"):
+                    transparency = self.info["transparency"]
                 bits = ord(self.fp.read(1))
                 self.__offset = self.fp.tell()
                 self.tile = [("gif",
                              (x0, y0, x1, y1),
                              self.__offset,
-                             (bits, interlace))]
+                             (bits, interlace, transparency))]
+                self.palette = ImagePalette.raw("RGB", self.currpal)
                 break
 
             else:
diff -Naur Imaging-1.1.6/decode.c Imaging-1.1.6-sam/decode.c
--- Imaging-1.1.6/decode.c	2006-12-03 12:51:26.000000000 +0100
+++ Imaging-1.1.6-sam/decode.c	2007-07-16 13:20:36.000000000 +0200
@@ -305,7 +305,8 @@
     char* mode;
     int bits = 8;
     int interlace = 0;
-    if (!PyArg_ParseTuple(args, "s|ii", &mode, &bits, &interlace))
+    int transparency = 0;
+    if (!PyArg_ParseTuple(args, "s|iii", &mode, &bits, &interlace, &transparency))
 	return NULL;
 
     if (strcmp(mode, "L") != 0 && strcmp(mode, "P") != 0) {
@@ -321,6 +322,7 @@
 
     ((GIFDECODERSTATE*)decoder->state.context)->bits = bits;
     ((GIFDECODERSTATE*)decoder->state.context)->interlace = interlace;
+    ((GIFDECODERSTATE*)decoder->state.context)->transparency = transparency;
 
     return (PyObject*) decoder;
 }
diff -Naur Imaging-1.1.6/libImaging/Gif.h Imaging-1.1.6-sam/libImaging/Gif.h
--- Imaging-1.1.6/libImaging/Gif.h	2006-12-03 12:37:26.000000000 +0100
+++ Imaging-1.1.6-sam/libImaging/Gif.h	2007-07-16 15:39:14.015329500 +0200
@@ -19,7 +19,10 @@
 typedef struct {
 
     /* CONFIGURATION */
-
+    
+    /* The transparent color */
+    int transparency;
+    
     /* Initial number of bits. The caller should clear all fields in
        this structure and set this field before calling the decoder
        the first time. */
diff -Naur Imaging-1.1.6/libImaging/Gif.h.bak Imaging-1.1.6-sam/libImaging/Gif.h.bak
--- Imaging-1.1.6/libImaging/Gif.h.bak	1970-01-01 01:00:00.000000000 +0100
+++ Imaging-1.1.6-sam/libImaging/Gif.h.bak	2007-07-16 13:19:31.500000000 +0200
@@ -0,0 +1,112 @@
+/*
+ * The Python Imaging Library.
+ * $Id: Gif.h 2134 2004-10-06 08:55:20Z fredrik $
+ *
+ * Declarations for a fast, suspendable GIF decoder.
+ *
+ * Copyright (c) Fredrik Lundh 1995-96.
+ */
+
+
+/* Max size for a LZW code word. */
+
+#define	GIFBITS	    12
+
+#define	GIFTABLE    (1<<GIFBITS)
+#define	GIFBUFFER   (1<<GIFBITS)
+
+
+typedef struct {
+
+    /* CONFIGURATION */
+    
+    /* 8-bit colorcode for frame transparency */
+    int transparency;
+    
+    /* Initial number of bits. The caller should clear all fields in
+       this structure and set this field before calling the decoder
+       the first time. */
+    int bits;
+
+    /* If set, this is an interlaced image.  Process it the following way:
+     * 1st pass: start at top line, lines are 8 pixels high, step 8 pixels
+     * 2nd pass: start at line 4, lines are 4 pixels high, step 8 pixels
+     * 3rd pass: start at line 2, lines are 2 pixels high, step 4 pixels
+     * 4th pass: start at line 1, lines are 1 pixels high, step 2 pixels
+     */
+    int interlace;
+
+    /* PRIVATE CONTEXT (set by decoder) */
+
+    /* Interlace parameters */
+    int step, repeat;
+
+    /* Input bit buffer */
+    INT32 bitbuffer;
+    int bitcount;
+    int blocksize;
+
+    /* Code buffer */
+    int codesize;
+    int codemask;
+
+    /* Constant symbol codes */
+    int clear, end;
+
+    /* Symbol history */
+    int lastcode;
+    unsigned char lastdata;
+
+    /* History buffer */
+    int bufferindex;
+    unsigned char buffer[GIFTABLE];
+
+    /* Symbol table */
+    unsigned INT16 link[GIFTABLE];
+    unsigned char data[GIFTABLE];
+    int next;
+
+} GIFDECODERSTATE;
+
+typedef struct GIFENCODERBLOCK_T
+{
+    struct GIFENCODERBLOCK_T *next;
+    int size;
+    UINT8 data[255];
+} GIFENCODERBLOCK;
+
+typedef struct {
+
+    /* CONFIGURATION */
+
+    /* Initial number of bits. The caller should clear all fields in
+       this structure and set this field before calling the encoder
+       the first time. */
+    int bits;
+
+    /* NOTE: the expanding encoder ignores this field */
+
+    /* If set, write an interlaced image (see above) */
+    int interlace;
+
+    /* PRIVATE CONTEXT (set by encoder) */
+
+    /* Interlace parameters */
+    int step, repeat;
+
+    /* Output bit buffer */
+    INT32 bitbuffer;
+    int bitcount;
+
+    /* Output buffer list (linked list) */
+    GIFENCODERBLOCK* block; /* current block */
+    GIFENCODERBLOCK* flush; /* output queue */
+    GIFENCODERBLOCK* free; /* if not null, use this */
+
+    /* Fields used for run-length encoding */
+    int first; /* true if we haven't read the first pixel */
+    int last; /* last byte value seen */
+    int count; /* how many bytes with that value we've seen */
+    int lastcode;
+
+} GIFENCODERSTATE;
diff -Naur Imaging-1.1.6/libImaging/GifDecode.c Imaging-1.1.6-sam/libImaging/GifDecode.c
--- Imaging-1.1.6/libImaging/GifDecode.c	2006-12-03 12:37:26.000000000 +0100
+++ Imaging-1.1.6-sam/libImaging/GifDecode.c	2007-07-16 15:35:37.343454500 +0200
@@ -265,16 +265,22 @@
 	   some common cases and handle them separately. */
 
 	/* FIXME: should we handle the transparency index in here??? */
+    /* Yes you should. - Sam */
+    /* It wouldn't work to copy a whole line with transparency though, so i've commented that out.  */
 
 	if (i == 1) {
 	    if (state->x < state->xsize-1) {
 		/* Single pixel, not at the end of the line. */
-		*out++ = p[0];
+		if (p[0] != context->transparency) {
+            *out = p[0];
+        }
+        out++;
 		state->x++;
 		continue;
 	    }
-	} else if (state->x + i <= state->xsize) {
-	    /* This string fits into current line. */
+	} 
+    /*else if (state->x + i <= state->xsize) {
+	    // This string fits into current line.
 	    memcpy(out, p, i);
             out += i;
 	    state->x += i;
@@ -282,11 +288,14 @@
 		NEWLINE(state, context);
 	    }
 	    continue;
-	}
+	}*/
 
 	/* No shortcut, copy pixel by pixel */
 	for (c = 0; c < i; c++) {
-	    *out++ = p[c];
+        if (p[c] != context->transparency) {
+            *out = p[c];
+        }
+        out++;
 	    if (++state->x >= state->xsize) {
 		NEWLINE(state, context);
 	    }
