Showing the Colour Table of a GIF.

This script will display the colours in the colour table used by the first frame of a GIF.

                                                                
                                                                
                                                                
                                                                
                                                                
                                                                
                                                                
                                                                
                                                                
                                                                
                                                                
                                                                
                                                                
                                                                
                                                                
                                                                

The script can be downloaded here - showpalette.zip. The image path is hard coded but this can easily be changed to read an image of your choice. To run the script the trial version of the csASPGif component must be registered. Click Here to download the component.

This is the GIF image.

Here is a listing of the script. Much of it is devoted to making the colours display in a square table and this is done by counting the rows and columns. The GIF could use a Global Colour Table or a Local Colour Table and this is taken care of with an If..Then..Else statement. If a multi-frame GIF was loaded only the first frame would be used.

<%
Set Gif = Server.CreateObject("csASPGifTrial.Gif")
Gif.ReadFile Server.MapPath("./images/rabbit.gif")
Response.Write "<table>"
If Gif.ColorDepth = 1 Then
  Rows = 1
  Columns = 2
Else
  If Gif.ColorDepth = 4 Then
    Rows = 1
    Columns = 16
  Else
    Rows = 16
    Columns = 16
  End If
End If
CurrentRow = 0
While CurrentRow <> Rows
  CurrentColumn = 0
  Response.Write "<tr>"
  While CurrentColumn <> Columns
    Index = (CurrentColumn) + (CurrentRow) * 16
    If Gif.HasGCT = True Then
      Response.Write "<td bgcolor=#" & Gif.GCTEntry(Index) &_
">&nbsp;&nbsp;&nbsp;&nbsp;</td>"
    Else
      Response.Write "<td bgcolor=#" & Gif.LCTEntry(0, Index) &_
">&nbsp;&nbsp;&nbsp;&nbsp;</td>"
    End If
      CurrentColumn = CurrentColumn + 1
  Wend
  CurrentRow = CurrentRow + 1
  Response.Write "</tr>"
Wend
Response.Write "</table>"
%>

Cookies

This site uses cookies for functionality, traffic analysis and for targeted advertising. Click the Accept button to accept our Cookie Policy. The Cookie Policy page offers configuration for a reduced set of cookies for this site.