- About Graphics Mill
- What's New?
- Breaking Changes in Graphics Mill 12
- Breaking Changes in Graphics Mill 11
- Features
- Supported File Formats
- System Requirements
- Getting Started
- Working with Image Formats
- Transforming Images (Resize, Rotate, Crop)
- Working with Metadata
- Color Management and Color Reduction
- Drawing Text and Graphics
- Color Keying (Green Screen Removal)
- Channels and Pixel Data
- Color and Tone Correction
- Working with Photoshop (PSD) Files
- Image Filters
- Processing Large Images
- Basics of Image Processing
- Troubleshooting
- Class Library Reference
- Licensing
- End User License Agreement
- Copyright Notices
Loading Text Layers
Graphics Mill supports loading layers of different types from PSD files. Text layers store a text string and its appearance settings (font, color, paragraph, etc.) along with a bitmap. You can create personalized graphics by using text layers as placeholders in a PSD template. Just change text in a placeholder and merge PSD file layers. This article describes how to work with text layers, including transformed text and text on a curve.
Common Text Settings
To start reading a PSD file use the PsdReader(String) constructor, which accepts a filename as an argument.
While a PSD file is opened by Graphics Mill, no other application can delete or modify the file.
To access layers use the PsdReader.Frames property which returns a collection of PsdFrame instances. A text layer is represented by the PsdTextFrame class which extends the PsdFrame class with a text-specific functionality. For each text layer the following data can be obtained:
- text color (Color),
- text font name and size (the FontName and FontSize properties),
- text string itself (the Text property),
- text region location and size (the TextBox property),
- text caps settings (the Caps property),
- spacing between characters (the PsdTextFrame.Tracking property),
- whether the text is vertical (the IsVertical property),
- paragraph settings (the Paragraph property):
- left margin indent (the ParagraphSettings.LeftIndent property),
- right margin indent (the ParagraphSettings.RightIndent property),
- first line indent (the ParagraphSettings.FirstLineIndent property),
- space before the paragraph (the ParagraphSettings.SpaceBeforeParagraph property),
- space after the paragraph (the ParagraphSettings.SpaceAfterParagraph property),
- text alignment (the PsdTextFrame.Justification property).
The following code reads a PSD file, iterates through its layers, and writes some information about a text layer to the console:
//create PSD reader
using (var reader = new PsdReader(@"Images\BusinessCard.psd"))
{
//read layers and check for a text layer
for (int i = 0; i < reader.Frames.Count; i++)
{
using (var frame = reader.Frames[i])
{
if (frame.Type == FrameType.Text)
{
var textFrame = (PsdTextFrame) frame;
Console.WriteLine("Font name: " + textFrame.FontName);
Console.WriteLine("Font size: " + textFrame.FontSize);
Console.WriteLine("Text caps: " + textFrame.Caps);
Console.WriteLine("Text justification: " + textFrame.Justification);
Console.WriteLine("Paragraph first line indent: " + textFrame.Paragraph.FirstLineIndent);
Console.WriteLine("Text tracking: " + textFrame.Tracking);
Console.WriteLine("Text box: " + textFrame.TextBox);
break;
}
}
}
}
Text on Curves and Transformed Text Settings
For transformed and curved text additionally you can extract
- the curve which the text is located along (the PsdTextFrame.Path property),
- layer transformation matrix (the PsdTextFrame.Transform property),
The following code reads a PSD file, iterates through its layers, and writes information to the console about a curve which the curved text is located along:
//create PSD reader
using (var reader = new PsdReader(@"Images\Seal.psd"))
{
//read layers and check for a text layer
for (int i = 0; i < reader.Frames.Count; i++)
{
using (var frame = reader.Frames[i])
{
if (frame.Type == FrameType.Text)
{
var textFrame = (PsdTextFrame)frame;
Console.WriteLine("Text path length in pixels: " + textFrame.Path.GetLength());
if (textFrame.Path.Points.Count > 0)
{
Console.WriteLine("Text path points: ");
for (int j = 0; j < textFrame.Path.Points.Count; j++)
Console.WriteLine("point " + j + ": " + textFrame.Path.Points[j].Type + " (" +
textFrame.Path.Points[j].X + ";" + textFrame.Path.Points[j].Y + ") ");
}
Console.WriteLine("Text box: " + textFrame.TextBox);
// break;
}
}
}
}
For more information about the paths, see the Working with Paths topic.
To get a layer transformation matrix you can do as follows:
//create PSD reader
using (var reader = new PsdReader(@"Images\Seal.psd"))
{
//read layers and check for a text layer
for (int i = 0; i < reader.Frames.Count; i++)
{
using (var frame = reader.Frames[i])
{
if (frame.Type == FrameType.Text)
{
var textFrame = (PsdTextFrame)frame;
Console.WriteLine("Text transformation matrix: ");
var matrix = textFrame.Transform.Elements;
Console.WriteLine("( " + matrix[0] + " " + matrix[2] + " " + matrix[4] + " )");
Console.WriteLine("( " + matrix[1] + " " + matrix[3] + " " + matrix[5] + " )");
// break;
}
}
}
}
For more information about transformation matrices, see the Affine and Projective Transformations topic.