Personalize Adobe Photoshop (PSD) files using PsdProcessor

Last week we have released the new version 8 of Graphics Mill. One of the main improvements is the new PsdProcessor class which allows process Adobe Photoshop (PSD) files much easier than earlier.

Please note that this functionality is available in Customer's Canvas — the other product by Aurigma. Learn more...

Photoshop is a standard de facto for creating and editing graphics files. One of the features people love in Adobe’s software is an ability to split graphics into layers and create composite images. Photoshop creates raster, vector and text layers, masks, alpha compositing, RGB, CMYK and Lab color spaces and many other features.

So Photoshop gives really endless possibilities to graphics designers. A lot of them use Photoshop to create print product templates, like business cards, marketing materials, etc. However the problem is that Photoshop is a really complicated software and if you want to pick a business card PSD template and fill in person details, you need a help from a skilled designer.

Obviously, it would be a smart idea to automate this process - have a designer to create a template and just replace the data in text layers. But how to do it?

Partially it can be solved with a help of merging functionality built in Adobe Photoshop or even go further using scripting automation. The problem is that it requires Adobe’s software installed. And it is definitely not an option on server environment.


We created the PsdProcessor class in Graphics Mill to solve the problem and let a common C# developer without special image processing skills to automate image template processing.

Historically, Graphics Mill supports PSD file format very well. It allowed extracting raster and text layers using the PsdReader class very long time. So you could just iterate all layers and combine them together by drawing them each over other. If you especially simplified PSD files, flattened all effects and masks, etc, you would get very similar results. Many other customers used this functionality in their web-to-print solutions to allow their customers personalizing templates.

With each new release, Graphics Mill could extract more and more information from PSD files. It started to support formatted and text on path, vector mask and Smart Object, effects and transforms. Eventually we have found out that it is not so simple to render a template using all the data we fetch from a PSD file. You had to write a mini-Photoshop to do it!

Merge PSD files

This is where PsdProcessor comes into a game. It reads text, raster and shape layers and it automatically merges them together using masks, opacity, transforms and effects. You can load PSD and combine all its layers into a JPEG or PDF very easily:

var psdProcessor = new PsdProcessor();  
psdProcessor.Render("BusinessCard.psd", "BusinessCard.pdf");
Original business card

Personalize PSD files

However rendering the original PSD file is not so interesting. A real magic begins when you want to modify the content of some layers.

With PsdProcessor, you can do it by defining a callback which is called for every layer. For example:

var psdProcessor = new PsdProcessor();  
psdProcessor.StringCallback = (processor, textFrame) =>  
    if (textFrame.Name == "FullName")  
        return "John Doe";  
    return textFrame.Text;  
psdProcessor.Render("BusinessCard.psd", "BusinessCard.pdf");  
Modified business card

Here you define a function which is called for each text layer and whenever it means a layer named FullName, it inserts a person’s name into it. That’s it!

Of course, you are not limited by text layers. You can create callbacks for all layer types supported by Graphics Mill - raster, text, shape and Smart Object layers. You can find the more information in the documentation.

Raster or vector output format

As you noticed, Graphics Mill supports shape layers, i.e. vector data. You may wonder whether you have to rasterize it within Graphics Mill or keep it vector.

The good news is that Graphics Mill smart enough to preserve vector when it is possible. If you specify the output format as, say, TIFF, PNG or JPEG, the image will be rasterized. However if you export it as PDF, the vector image will be saved. For example we can generate 100% vector seal base on text and shape layers:

Vector output

Fix missing fonts using the FontResolver and font source

PsdProcessor solves another annoying problem - missing fonts. Designers love to use beautiful typography and if you want templates to render properly, you have to make sure that a proper font is installed on your server.

Not anymore with PsdProcessor! It automatically detects missing fonts and searches it in various sources - local folders (no need to install them, just put TrueType, OpenType or WOFF files), Font Squirrel and of course Google Fonts!

var fontResolver = new FontResolver(@"C:\Cache");  
fontResolver.AddSource(new FileSystemSource(@"C:\Fonts"));  
fontResolver.AddSource(new GoogleFontSource("x..x-y..y-z..z"));  
fontResolver.AddSource(new SquirrelFontSource());  
var psdProcessor = new PsdProcessor(fontResolver);  
psdProcessor.Render("BusinessCard.psd", "BusinessCard.pdf");


The PsdProcessor makes PSD template processing very simple for any C# developer. No need to struggle with imaging problems, just concentrate on a business logic.

In the next post, I will tell how to create pseudo-3D mockups with a help of Smart Object loaded from PSD files.