saveImage() GIF option



  • hi guys,
    does anybody know how 'imageGIFRGBColorTable' works?
    i mean, which ones are the possible arguments? i would need an example to see.
    ex.:

    saveImage(img_folder+name+extension, imageGIFRGBColorTable=???)
    

    (I tried =24, ="24-bit" …i know, stupid trials)

    thanks a lot


  • admin

    I'm not a color or gif expert. But this works:

    # see http://www.cocoabuilder.com/archive/cocoa/104713-nsimagergbcolortable-crash.html
    newPage(100, 100)
    
    linearGradient(
                (0, 0),                         # startPoint
                (100, 100),                         # endPoint
                [(1, 0, 0), (0, 0, 1), (0, 1, 0)],  # colors
                [0, .2, 1]                          # locations
                )
    rect(0, 0, 100, 100)
        
    fill(1, 0, 0)
    rect(20, 20, 20, 20)
    
    fill(0, 1, 0)
    rect(100-40, 20, 20, 20)
    
    fill(0, 0, 1)
    rect(100-40, 100-40, 20, 20)
    
    fill(0, 1, 1)
    rect(20, 100-40, 20, 20)
    
    
    import struct
    
    table = b""
    
    for i in range(256):
        r = struct.pack(">B", 30)
        g = struct.pack(">B", i)
        b = struct.pack(">B", 255)
        #a = struct.pack(">B", 254) # use if imageGIFDitherTransparency is True 
        table += r + g + b # + a
    
    # table must have a size of 768 
    # or 1024 when imageGIFDitherTransparency is True
    print(len(table))
    
    test = '~/Desktop/testGif.gif'
    saveImage(test, imageGIFRGBColorTable=table)
    
    newPage(100, 100)
    image(test, (0, 0))
    

Log in to reply