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

PSD Smart Object - UpdateText

Hello,
I have an example .psd file here.
This file consists of a Smartobject with a TextLayer.
How can I access and modify the text so that the formatting is preserved?

https://www.xup.in/dl,21517984/test.psd/


I have only found the solution to save a new text as an image. But I'm losing the formatting.
Hi,

The Smart Object layer contains another PSD file, so you should just render the PSD file recursively.

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

class Program
{
	static void Main(string[] args)
	{
		//Render the main PSD file
		var mainPsdProcessor = new PsdProcessor();
			
		mainPsdProcessor.FrameCallback = (mainProcessor, frame) =>
		{
			if (frame.Type != FrameType.SmartObject || frame.Name != "Surname")
				return mainProcessor.ProcessFrame(frame);

			//Render the PSD file contained in the Smart Object layer
			using (var smartFrame = (PsdSmartFrame)frame)
			using (var smartFrameInputStream = smartFrame.GetData())
			using (var smartFrameOutputStream = new MemoryStream())
			{
				var smartFramePsdProcessor = new PsdProcessor();

				smartFramePsdProcessor.StringCallback = (subProcessor, textFrame) =>
				{
					var textString = textFrame.GetFormattedText();

					if (textFrame.Name == "Name")
						textString = "Hello";

					return textString;
				};

				smartFramePsdProcessor.Render(smartFrameInputStream, smartFrameOutputStream, new TiffSettings());

				return smartFrame.ToGraphicsContainer(ImageReader.Create(smartFrameOutputStream),
					ResizeMode.ImageFill);
			}
		};

		mainPsdProcessor.Render(@"../../../Test.psd", @"../../../out.tif");
	}
}


If something is unclear please let me know.
Thank you very much. That's how it works.
Unfortunately, it does not take on the "smart filter".
I have another Test.psd created with a few filters.
Could you test this with you?

https://www.xup.in/dl,53366082/test.psd/
Hi,

Currently, we don't support Smart Filter. If this functionality is critical for you please contact us.
I tested effects directly at the text level.
If I only use the "Drop Shadow" then it works.
But as soon as I use an effect like "Inner Glow" I get an exception.

smartFramePsdProcessor.Render(smartFrameInputStream, smartFrameOutputStream, new TiffSettings());
System.ArgumentNullException:
We don't support the inner glow effect, but its processing should not cause an exception. Could you send us the PSD file you tested?
My goal is to edit the text of several text layers.
Additionally, filters like "Outer Glow" and / or "Blur" should be applied directly and ONLY on the text.
Then a .png is created from this one is then additionally processed completely with the filter "Blur".
If no smart filters work.
Then I have to replace the smart objects with TextLayer and switch the filters manually.
But it should work dynamically.
I have several PSD files with the same fields but they always have different positions.

Is there any other solution?
You can slightly modify the above code to imitate smart filters:

				//Apply blur directly (insted of smart filter)
				var bitmap = new Bitmap(smartFrameOutputStream);
				bitmap.Transforms.Blur(5);

				return smartFrame.ToGraphicsContainer(bitmap,
					ResizeMode.ImageFill);


Here is the full code sample:

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

class Program
{
	static void Main(string[] args)
	{
		//Render the main PSD file
		var mainPsdProcessor = new PsdProcessor();
			
		mainPsdProcessor.FrameCallback = (mainProcessor, frame) =>
		{
			if (frame.Type != FrameType.SmartObject || frame.Name != "Surname")
				return mainProcessor.ProcessFrame(frame);

			//Render the PSD file contained in the Smart Object layer
			using (var smartFrame = (PsdSmartFrame)frame)
			using (var smartFrameInputStream = smartFrame.GetData())
			using (var smartFrameOutputStream = new MemoryStream())
			{
				var smartFramePsdProcessor = new PsdProcessor();

				smartFramePsdProcessor.StringCallback = (subProcessor, textFrame) =>
				{
					var textString = textFrame.GetFormattedText();

					if (textFrame.Name == "Name")
						textString = "Hello";

					return textString;
				};

				smartFramePsdProcessor.Render(smartFrameInputStream, smartFrameOutputStream, new TiffSettings());

				//Apply blur directly (insted of smart filter)
				var bitmap = new Bitmap(smartFrameOutputStream);
				bitmap.Transforms.Blur(5);

				return smartFrame.ToGraphicsContainer(bitmap,
					ResizeMode.ImageFill);
			}
		};

		mainPsdProcessor.Render(@"../../../Test.psd", @"../../../out.tif");
	}
}


If you need to process smart filters automatically we can consider to implement it as custom work.
Fedor;32848

If you need to process smart filters automatically we can consider to implement it as custom work.


Yes, it would be very nice.
An automatic takeover of the filters is exactly what I need, then I could use and buy this API.
When is it ready?
Fedor;32848
An automatic takeover of the filters is exactly what I need, then I could use and buy this API.
When is it ready?


Please contact us at info@aurigma.com for the information.
Fedor;32838
Hi,

The Smart Object layer contains another PSD file, so you should just render the PSD file recursively.

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

class Program
{
	static void Main(string[] args)
	{
		//Render the main PSD file
		var mainPsdProcessor = new PsdProcessor();
			
		mainPsdProcessor.FrameCallback = (mainProcessor, frame) =>
		{
			if (frame.Type != FrameType.SmartObject || frame.Name != "Surname")
				return mainProcessor.ProcessFrame(frame);

			//Render the PSD file contained in the Smart Object layer
			using (var smartFrame = (PsdSmartFrame)frame)
			using (var smartFrameInputStream = smartFrame.GetData())
			using (var smartFrameOutputStream = new MemoryStream())
			{
				var smartFramePsdProcessor = new PsdProcessor();

				smartFramePsdProcessor.StringCallback = (subProcessor, textFrame) =>
				{
					var textString = textFrame.GetFormattedText();

					if (textFrame.Name == "Name")
						textString = "Hello";

					return textString;
				};

				smartFramePsdProcessor.Render(smartFrameInputStream, smartFrameOutputStream, new TiffSettings());

				return smartFrame.ToGraphicsContainer(ImageReader.Create(smartFrameOutputStream),
					ResizeMode.ImageFill);
			}
		};

		mainPsdProcessor.Render(@"../../../Test.psd", @"../../../out.tif");
	}
}


If something is unclear please let me know.


I have this error => System.ObjectDisposedException: 'Cannot access a disposed object.
Please submit a case regarding the problem. Don't forget to attach the PSD file you process as well as refer this post.