# Preview

This section describes how to prepare a channel to support previews. In the GUI a preview is generated when you click the preview button in the graph canvas. You can also test preview locally by including the "--preview" flag on the ana command that runs the channel.

To determine if a given run of a channel is in preview mode, you should check the context variable 'preview'. This will be set to True if the channel should generate a preview image. Typically this is done by taking the rendered image and generating a copy called "preview\.png". The preview image should be stored in the root of the output directory.

Channels should be optimized so that preview times are minimal. This includes such things as reducing the number of render samples and decreasing the resolution of the image.

Here is an example of a blender channel that generates a preview. This code is in the render node that generates the image. It lowers the sample count to 10, cuts the resolution of the preview image in half, and also doesn't write annotation or metadata if preview is set. Note the node has one input which is a pointer to the AnaScene object.

```python
from anatools.lib.node import Node
import anatools.lib.context as ctx
from PIL import Image, ImageFile

class Render(Node):
     def exec(self):
        ana_scene = self.inputs["Scene"][0]
        # cut the resolution in half
        if ctx.preview:
            bpy.context.scene.cycles.samples = 10
            bpy.context.scene.render.resolution_x = int(bpy.context.scene.render.resolution_x / 2)
            bpy.context.scene.render.resolution_y = int(bpy.context.scene.render.resolution_y / 2)
        # render the image
        bpy.ops.render.render(write_still=True, scene=ana_scene.blender_scene.name)
        # generate preview image
        if ctx.preview:
            filename = f'{ctx.interp_num:010}-{ana_scene.blender_scene.frame_current}-{ana_scene.sensor_name}.png'
            image_file = os.path.join(ctx.output, "images", filename)
            image = Image.open(image_file)
            image.save( os.path.join(ctx.output,"preview.png") )
        else:
            ana_scene.write_ana_annotations()
            ana_scene.write_ana_metadata()
        return {}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://support.rendered.ai/development-guides/ana-software-architecture/preview.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
