Vizard 8 » Reference » Appearance & Texturing » Python Imaging Library
8.1

Python Imaging Library (PIL)

Use the Python Imaging Library (PIL) to add image processing capabilities to your Vizard scripts. You can process an image and then load it as a texture within Vizard. Cutting, pasting, and merging images, rotating and resizing images, and image enhancement are some examples of what you can do.

 

For a complete description of the commands available within the library refer to the PIL Documentation.

Example

The following example shows how to take a PIL image and use it as a Vizard texture. We create a new PIL image, draw an ellipse onto it, and then add some text. The PIL_TO_VIZARD function then copies this PIL image to a Vizard texture:

import viz
from PIL import Image, ImageDraw

viz.go()

def PIL_TO_VIZARD(image,texture):
    """Copy the PIL image to the Vizard texture"""
    im = image.transpose(Image.FLIP_TOP_BOTTOM)
    texture.setImageData(im.convert('RGB').tobytes(),im.size)

#Create a blank Vizard texture
tex = viz.addBlankTexture([1,1])

#Apply texture to quad
quad = viz.addTexQuad(pos=(0,1.8,2),texture=tex)

#Create a new PIL image and add a shape and text to it
image = Image.new(mode='RGB',size=(200,200),color=(0,0,255))
draw  =  ImageDraw.Draw(image)
draw.ellipse((50,50,150,150),fill=(255,255,255))
draw.text((85,95),'HELLO',fill=(0,0,0))

#Copy PIL image to Vizard texture
PIL_TO_VIZARD(image,tex)