1. NodeBox 1
    1. Homepage
    2. NodeBox 3Node-based app for generative design and data visualization
    3. NodeBox OpenGLHardware-accelerated cross-platform graphics library
    4. NodeBox 1Generate 2D visuals using Python code (Mac OS X only)
  2. Gallery
  3. Documentation
  4. Forum
  5. Blog

exporting to .gif ?

Posted by nunia on May 29, 2007

this is my wish list. Can nodebox add exporting to .gif as another format? QuickTime movie files are a bit _fat_ ...


 
Posted by Tom De Smedt on May 29, 2007

Hi Nunia,

Here is a script that exports images from NodeBox:

from AppKit import *
 
def export(name, extension=".jpg", compression=0.7):
    
    try:
        # Exporting only works from the second run.
        img = _ctx._ns["graphicsView"].image
    except:
        return
    img = img.TIFFRepresentation()
    img = NSBitmapImageRep.imageRepWithData_(img)
 
    options = None
    if extension == ".gif":
        type = SGIFFileType
    if extension == ".png":
        type = NSPNGFileType
    if extension == ".jpg":
        type = NSJPEGFileType
        options = {NSImageCompressionFactor: compression}
    
    data = img.representationUsingType_properties_(type, options)
    f = open(name+extension, "w")
    f.write(data.bytes())
    f.close()
 
# Now draw some things on the canvas.
size(400,400)
background(None)
for i in range(100):
    fill(random())
    oval(random(WIDTH), random(HEIGHT), 100, 100)
    
# Export it to file, you can choose .jpg, .gif and .png!
# The file will be in the same folder as the script.
# Remember, export only works from the second time
# you run the code.
export("test", extension=".png")
Enjoy!



Posted by nunia on May 29, 2007

thanks! this can be _very_ handy.

I also installed iSquint which shrinks 96M .mov to 500k .mp4. Sweet!



Posted by Frido on Sep 18, 2007

Lifesaver! Thx