anyone else wrap gd-1.8?

Les Schaffer godzilla at
Sat Mar 11 17:35:10 CET 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

I noticed the gdmodule link on

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: 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. 

# Destroy the image in memory. 

More information about the Python-list mailing list