PyX — Example: bitmap/pil.py

0.3 KB
1.9 KB
0.5 KB
1.0 KB

Using image instances from the PIL

pil.png
from pyx import *
from PIL import Image

im = Image.new("RGB", (3, 1))
im.putpixel((0, 0), (255, 0, 0))
im.putpixel((1, 0), (0, 255, 0))
im.putpixel((2, 0), (0, 0, 255))

c = canvas.canvas()
c.insert(bitmap.bitmap(0, 0, im, height=0.8))
c.writeEPSfile("pil")
c.writePDFfile("pil")

Description

You can use image instances from the Python Image Library to create bitmaps. You then have an easy access to all the bitmap formats available in PIL, you may also use PIL features to create/load/modify bitmaps etc. In order to create an image pixel by pixel, the PIL is not necessary (by the way, it is slow to use putpixel for that).

Using PIL image instances you can also pass indexed images to PyX's bitmap class.