---
title: "Render Mug Preview"
canonical: https://www.graphicsmill.com/samples/PSDFormat/Create3DPreview/RenderMugPreview_cs
product: "Graphics Mill"
source: "PSDFormat/Create3DPreview/RenderMugPreview.cs"
---

# Render Mug Preview

Creates 3D Preview of a customized mug using Adobe Photoshop's SmartObject.

## Instruction

This code processes a PSD file and handles the smart object frames by replacing them with an image.

## Usings

```csharp
using Aurigma.GraphicsMill.Codecs;
using Aurigma.GraphicsMill.Codecs.Psd;
using Aurigma.GraphicsMill.Templates;
using Aurigma.GraphicsMill.Transforms;
```

## Code Snippet

```csharp
var psdProcessor = new PsdProcessor();

psdProcessor.FrameCallback = (processor, frame) =>
{
    if (frame.Type != FrameType.SmartObject || frame.Name != "Design")
    {
        return processor.ProcessFrame(frame);
    }

    var smartFrame = (PsdSmartFrame)frame;

    return smartFrame.ToGraphicsContainer(
        ImageReader.Create("Copenhagen_RGB.jpg"),
        ResizeMode.ImageFill);
};

psdProcessor.Render("Mug.psd", "RenderMugPreview.png");
```

## Explanation

The code:

- Creates a `PsdProcessor` instance to process a PSD file (`Mug.psd`).
- Defines a `FrameCallback` function to handle each frame:
- If the frame is a smart object and has the name `"Design"`, it replaces that frame with an image (`Copenhagen_RGB.jpg`) resized to fit the frame using `ResizeMode.ImageFill`.
- Renders the processed PSD into a PNG file (`RenderMugPreview.png`).

## Tags

- [Personalization](<https://www.graphicsmill.com/samples/tags/personalization_md>): Replacing placeholders with dynamic content
- [PSD Processor](<https://www.graphicsmill.com/samples/tags/psd-processor_md>): Automating PSD-based personalization

## Input

- [Copenhagen\_RGB.jpg](<https://www.graphicsmill.com/samples/PSDFormat/compiled/Debug/Copenhagen_RGB_jpg>) (preview)
- [Mug.psd](<https://www.graphicsmill.com/samples/PSDFormat/compiled/Debug/Mug_psd>) (download)

## Output

- [RenderMugPreview.png](<https://www.graphicsmill.com/samples/PSDFormat/compiled/Debug/RenderMugPreview_png>) (preview)

## Used APIs

- [Aurigma.GraphicsMill.Codecs.ImageReader](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_ImageReader.htm.md>)
- [Aurigma.GraphicsMill.Codecs.ImageReader.Create(String)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Codecs_ImageReader_Create_1_bb3a7a4f.htm.md>)
- [Aurigma.GraphicsMill.Codecs.Psd.FrameType](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_Psd_FrameType.htm.md>)
- [Aurigma.GraphicsMill.Codecs.Psd.PsdFrame.Name](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_Psd_PsdFrame_Name.htm.md>)
- [Aurigma.GraphicsMill.Codecs.Psd.PsdFrame.Type](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_Psd_PsdFrame_Type.htm.md>)
- [Aurigma.GraphicsMill.Codecs.Psd.PsdSmartFrame](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_Psd_PsdSmartFrame.htm.md>)
- [Aurigma.GraphicsMill.Templates.PsdFrameExtensions.ToGraphicsContainer(PsdSmartFrame,Pipeline,ResizeMode,InterpolationMode)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Templates_PsdFrameExtensions_ToGraphicsContainer_4_4e17944c.htm.md>)
- [Aurigma.GraphicsMill.Templates.PsdProcessor](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Templates_PsdProcessor.htm.md>)
- [Aurigma.GraphicsMill.Transforms.ResizeMode](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_ResizeMode.htm.md>)
