anyone else wrap gd-1.8?

musingattheruins at my-deja.com musingattheruins at my-deja.com
Fri Apr 7 14:56:59 EDT 2000


Yeah, I wrapped it but did not use SWIG so it took longer than 1.25
hours.  It's available with source for Win32 at
http://musingattheruins.homepage.com/PythonGD.html

There's a compiled version or instructions for creating the module
yourself.  Uses the latest of everything (zlib, libpng, libjpg, and
gd). Also supports PNG and JPEG.

The compiled version (GD.pyd) is uncompressed and can just be dumped
into the \Program Files\Python\DLLs folder.  It does not create any
ancillary files or registry entries so to uninstall it just delete it.

Although I do not use keywords in parameters (maybe in a future
version) it does allow for tuples and __doc__ strings.

Also, image file pointers have been wrapped and access is through the
the file name and/or a python TYPE, which seems a little easier to read.

Regards,
Bill :-)


In article <m2wvn9pijt.fsf at netmeg.net>,
  Les Schaffer <godzilla at netmeg.net> wrote:
> 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)
>


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list