# NodeBox

Create visual output with Python programming code
Home Download Reference Tutorial Library Gallery About

# photobot.Canvas.layer()

## Syntax

    canvas.layer(image, x=0, y=0, name="")

## Description

Creates a new layer on the canvas from image, which is either the path of an image file (.jpg, .gif, .png) or a copied layer, or a PIL Image object. The image is positioned on the canvas horizontally at x pixels and vertically at y pixels measured from the top left corner. You can supply a name for the layer.

Returns the new layer index. Indices start at 1, this means the first layer is canvas.layers[1], the layer above canvas.layers[2] and so on. The bottom layer is reserved for the transparent background and must remain untouched.

## Example

Adds the image file robot.jpg as the top layer of canvas.

    photobot = ximport("photobot")
    canvas = photobot.canvas(100, 100)
    canvas.layer("images/robot.jpg")

Sets the opacity of the lowest layer in canvas.

    canvas.layers[1].opacity(60)