This forum contains outdated content and is available for reading only. Please contact technical support if you have any questions.

PSD file operation with Graphics Mill

Hi,

I am trying to investigate Graphics Mill product to use for our project. Mainly we want to load the PSD file and try to perform below action before saving into PNG file. Will we able to achieve following functionality on PSD file?

1. Change the color of psdShape frame at runtime.
2. Remove psdFrame i.e image? i think it can achived by returning null in FrameCallback. please confirm
3. Edit the text and color of the psdTextFrame? i could see color and text properties are protected
4. Replace psdSmartFrame(i.e image) with new image?
5. Replace current psdShape with new psdShape frame?

Will be able to achieve above functionality with Graphics Mill directly or any work around?
I have attached PSD file for reference.

attach #1341

attach #1342
Yes, you can implement all functionality using Graphics Mill.

Please see a code example:

using System;
using Aurigma.GraphicsMill;
using Aurigma.GraphicsMill.AdvancedDrawing;
using Aurigma.GraphicsMill.Templates;
using Aurigma.GraphicsMill.Codecs;
using Aurigma.GraphicsMill.Codecs.Psd;
using Aurigma.GraphicsMill.Transforms;

class Program
{
	static void Main(string[] args)
	{
		var psdProcessor = new PsdProcessor();

		//1. Change the color of psdShape frame at runtime.
		psdProcessor.ShapeCallback = (processor, frame) =>
		{
			if (frame.Name == "secondarycolor")
			{
				var shapeData = new ShapeData(frame);

				shapeData.Brush = new SolidBrush(RgbColor.Red);

				return shapeData;
			}

			return new ShapeData(frame);
		};

		psdProcessor.FrameCallback = (processor, frame) =>
		{
			//2. Remove psdFrame i.e image? i think it can achived by returning null in FrameCallback. please confirm
			if (frame.Name == "photo")
			{
				return null;
			}

			//4. Replace psdSmartFrame(i.e image) with new image?
			if (frame.Name == "logo")
			{
				var smartFrame = (PsdSmartFrame)frame;

				return smartFrame.ToGraphicsContainer(ImageReader.Create("../../../logo.png"),
					ResizeMode.ImageFill);
			}

			//5. Replace current psdShape with new psdShape frame?
			if (frame.Name == "Maincolor")
			{
				var container = new GraphicsContainer(600, 480, 72f, 72f);

				using (var graphics = container.GetGraphics())
				{
					var brush = new SolidBrush(RgbColor.SandyBrown);

					graphics.FillRectangle(brush, 0, 350, 640, 130);
				}

				return container;
			}


			return processor.ProcessFrame(frame);
		};

		//3. Edit the text and color of the psdTextFrame? i could see color and text properties are protected
		psdProcessor.TextCallback = (processor, frame, textString) =>
		{
			var text = processor.ProcessText(frame);

			if (frame.Name == "Phone")
			{
				text.String = "(555) 555-1234";
				text.Brush = new SolidBrush(RgbColor.Blue);

			}

			return text;
		};

		psdProcessor.Render("../../../photooverlay_5_02.psd", "../../../result.png");
	}
}


attach #1344

P.S. BTW, the layer "Maincolor" is rendered incorrectly. We will fix the problem in the future releases (Aurigma Bug #0023327). I will keep you informed of the status.
The bug #0023327 was fixed in the version 9.1.20 of Graphics Mill.