How to Change Font, Size, and Color in PSD Text Layer in .NET
Changing font family, text size, or color in PSD files is simple to automate with Aspose.PSD for .NET. This enables mass updates, rebranding, or template editing in seconds.
Real-World Problem
Brand guidelines, localization, or campaign changes may require updating fonts, sizes, or colors in hundreds of PSD templates—far faster to do in code than by hand.
Solution Overview
Use Aspose.PSD for .NET to locate and modify the text layer’s font, size, and color properties programmatically with a few lines of C#.
Prerequisites
- Visual Studio 2019 or later
- .NET 6.0 or later (or .NET Framework 4.6.2+)
- Aspose.PSD for .NET from NuGet
- PSD file with at least one editable text layer
PM> Install-Package Aspose.PSD
Step-by-Step Implementation
Step 1: Load the PSD File
using Aspose.PSD;
using Aspose.PSD.FileFormats.Psd;
using Aspose.PSD.FileFormats.Psd.Layers;
string inputFile = "./input/sample_with_text.psd";
string outputFile = "./output/sample_font_color_changed.psd";
var loadOptions = new PsdLoadOptions() { LoadEffectsResource = true };
PsdImage psdImage = (PsdImage)Image.Load(inputFile, loadOptions);
Step 2: Find and Edit the Text Layer
TextLayer textLayer = null;
foreach (var layer in psdImage.Layers)
{
if (layer is TextLayer t)
{
textLayer = t;
break;
}
}
if (textLayer == null)
{
throw new InvalidOperationException("No text layer found in PSD.");
}
// Change the font family
textLayer.Font = "Times New Roman";
// Change the font size
textLayer.FontSize = 36;
// Change the text color
textLayer.ForegroundColor = Color.Blue;
Step 3: Save the Edited PSD
psdImage.Save(outputFile);
psdImage.Dispose();
Use Cases and Applications
- Rebranding with new fonts/colors across all assets
- Campaign refresh with new text styles
- Automated localization for multiple markets
Common Challenges and Solutions
Fonts not available: Use only fonts installed on the server for perfect results.
No visible change: Make sure you’re targeting the right layer and property.
Best Practices
- Validate output in Photoshop
- Keep a backup of the original file
- Automate changes for many templates at once
FAQ
Q: Can I set bold or italic styles? A: Some styles are supported—check API Reference for advanced typography.
Q: Does this work for all text layers? A: Yes, as long as the layer is editable (not rasterized).
Conclusion
With Aspose.PSD for .NET, designers and developers can quickly apply consistent text styles across thousands of PSDs. For more, see the Aspose.PSD for .NET API Reference .