Generating a spacer gif on the fly

Max M maxm at mxm.dk
Wed Oct 9 06:29:04 EDT 2002


Max M wrote:
> I am writing an app where it would be practical to have a function that 
> generates a spacer gif in a given color::
> 
>     def spacer(color=''):
>         "Generates a 1x1 pixel gif with color, no color means transparent"


Oh well!

I took the brute force approach.

I created a transparent, red, green and blue gif in photoshop, created a 
list of byte values. Found the differences. From that it was easy to 
figure out what bytes to change.

Here it is, just for the record :)

def spacer(color=''):
     # Blank gif spacer template
     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
     return ''.join(map(chr, template))


regards Max M

 ><evolve>
   >    >




More information about the Python-list mailing list