public void writeAnimatedGIF(GIFFrame[] frames, OutputStream os) throws Exception {
    	// Header first
    	writeHeader(os, true);
    	
    	Rect logicalScreenSize = getLogicalScreenSize(frames);
    	
    	logicalScreenWidth = logicalScreenSize.width();
    	logicalScreenHeight = logicalScreenSize.height();
    	// We are going to write animated GIF, so enable animated flag
    	animated = true;
    	
    	for(int i = 0; i < frames.length; i++) {
    		// Retrieve image dimension
			int imageWidth = frames[i].getFrameWidth();
			int imageHeight = frames[i].getFrameHeight();
			int[] pixels = new int[imageWidth * imageHeight];
			frames[i].getFrame().getPixels(pixels, 0, imageWidth, 0, 0, imageWidth, imageHeight);
			if(frames[i].getTransparencyFlag() == GIFFrame.TRANSPARENCY_INDEX_SET && frames[i].getTransparentColor() != -1) {
				int transColor = (frames[i].getTransparentColor() & 0x00ffffff);				
				for(int j = pixels.length - 1; j > 0; j--) {
					int pixel = (pixels[j] & 0x00ffffff);
					if(pixel == transColor) pixels[j] = pixel; 
				}
			}
			writeFrame(pixels, imageWidth, imageHeight, frames[i].getLeftPosition(), frames[i].getTopPosition(),
					frames[i].getDelay(), frames[i].getDisposalMethod(), frames[i].getUserInputFlag(), os);
    	}
    	
    	os.write(IMAGE_TRAILER);
		os.close();    	
    }
Writes an array of GIFFrame as an animated GIF

@param frames an array of GIFFrame
@param os OutputStream for the animated GIF
@throws Exception
subs/gif-revert/src/main/java/com/engineer/gif/revert/lib/AnimatedGIFWriter.java