anyone else wrap gd-1.8?

Les Schaffer godzilla at netmeg.net
Sat Mar 11 11:35:10 EST 2000


I just wrapped the latest gd module -- version 1.8 which now handles
both png and jpeg file formats -- into python. It was quite easy with
SWIG.

I noticed the gdmodule link on 

http://www.python.org/topics/scicomp/plotting.html

is dead. has anyone else wrapped gd up lately? otherwise i am happy to
distribute (all 1.25 hours of my accumulated time :-)

les schaffer

this gives you an idea what you can do:

#!/usr/bin/python -O

from gd import *

# this demo taken __straight__ from the gd sample demo on boutell's GD
# home page: http://www.boutell.com/gd and pythonized

# Allocate the image: 64 pixels across by 64 pixels tall 
im = gdImageCreate(64, 64)

# Allocate the color black (red, green and blue all minimum).
# Since this is the first color in a new image, it will
# be the background color. 
black = gdImageColorAllocate(im, 0, 0, 0)

# Allocate the color white (red, green and blue all maximum). 
white = gdImageColorAllocate(im, 255, 255, 255)  
        
# Draw a line from the upper left to the lower right,
# using white color index. 
gdImageLine(im, 0, 0, 63, 63, white)

# Open a file for writing. "wb" means "write binary"
pngout = fopen("test.png", "wb")

# Do the same for a JPEG-format file.
jpegout = fopen("test.jpg", "wb")

# Output the same image in JPEG format, using the default
# JPEG quality setting. 
gdImageJpeg(im, jpegout, -1)

# Output the image to the disk file in PNG format. 
gdImagePng(im, pngout)

# Close the files. 
fclose(pngout)
fclose(jpegout)

# Destroy the image in memory. 
gdImageDestroy(im)



More information about the Python-list mailing list