.gif color dot

I don't know who made this code, but it generates a one-pixel GIF of a specified color. This is useful for things like HTML barcharts, where you can specify the height of a bar by defining the height of a one-pixel image. -FW

"Lightweight Web techniques" [1 ] illustrates a use of color dots.

Primitive:

    proc make_color_dot color {
        return \x47\x49\x46\x38\x37\x61\x01\x00\x01\x00\x91\x00$color\xff\xff\xff\xff\xff\xff\xff\xff\xff\x2c\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3b\x00
            # Hmmm.  In February 2003, CL couldn't get the sequence
            #    above to work as expected, and resorted instead to
        set BEFORE "\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x00\x00"
        set AFTER="\x00\x00\x00\x21\xf9\x04\x00\x00\x00\x00\x00\x2c\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3b\x00"
        return $BEFORE$color$AFTER
            # Presumably someone with enough motivation can track
            #    these back to the pertinent standards.
    }


    proc write_color_dot {color filename} {
        set fp [open $filename w]
        puts -nonewline $fp [make_color_dot $color]
        close $fp
    }


    write_color_dot \x00\x00\xff\x00 /tmp/gif/green.gif

MGS I've used this to write a 1x1 transparent gif image:

    set data "GIF89a\u0001\u0000\u0001\u0000\u00A1\u0001\u0000\u0000\u0000\u0000\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u00FF\u0021\u00F9\u0004\u0001\u000A\u0000\u0001\u0000\u002C\u0000\u0000\u0000\u0000\u0001\u0000\u0001\u0000\u0000\u0002\u0002\u004C\u0001\u0000;"

Lars H: With \x in place of the \u00's (no need to worry about \x grabbing more than two digits), that would become

    set data "GIF89a\x01\x00\x01\x00\xA1\x01\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x21\xF9\x04\x01\x0A\x00\x01\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x4C\x01\x00;"

More compact still is to use binary:

    set data [binary format a*H*a GIF89a 01000100A10100000000FFFFFFFFFFFFFFFFFF21F904010A0001002C00000000010001000002024C0100 ";"]

[Write up Tk example for simply putting color on PhotoImage.]

MG offers:

  set img [image create photo -height 1 -width 1]
  $img write $chosenPath -background $colour -format gif
  image delete $img ; unset img ;# cleanup

Pythonic expression of same:

     template = [71, 73, 70, 56,  57, 97, 1,  0, 1, 0, 128, 0, 0, 255, 255, 255,
                 0, 0, 0,  33, 249, 4, 1, 0, 0, 0, 0, 44, 0, 0, 0, 0, 1, 0, 1,
                 0, 0, 2, 2, 68, 1, 0, 59]
     if color:
         rgb = [63, 127, 255] # will be calculated later
         template[13:16] = rgb
         template[22] = 0 # remove transparency    

Modern Web programming deprecates spacer gif-s in favor of CSS positioning.