Working with smart objects

@aspose_psd

We have shared the possible option with you. Unfortunately, you faced issue while saving the file. Therefore, I request you to please be patient and we will share the good news with you as soon as the issues will be fixed.

Is any good news?

@aspose_psd

Can you please consider using latest Aspose.PSD for .NET 20.12 on your end with following code for the above stated issue.

            const string baseFolder = "PSDNET792_1\\";
            const string outputFolder = baseFolder + "output\\";
            string sourceFilePath = baseFolder + "1.psd";
            string outputFilePath = outputFolder+ "1_output.psd";
            string outputPngFilePath = Path.ChangeExtension(outputFilePath, ".png");
            PsdLoadOptions options = new PsdLoadOptions() { LoadEffectsResource = true };
            using (PsdImage image = (PsdImage)Image.Load(sourceFilePath, options))
            {
                var length = image.Layers.Length;
                for (int i = 0; i < length; i++)
                {
                    // Looking for Smart Object
                    var smart = image.Layers[i] as SmartObjectLayer;
                    if (smart != null && smart.Name == "__D__")
                    {
                        // We are loading Smart Object Layer from Memory Stream,
                        // But we can use smart smart.ExportContents(somePath) to export smart object to file
                        using (var stream = new MemoryStream(smart.Contents))
                        {
                            stream.Position = 0;
                            using (var imageInSmart = (PsdImage)Image.Load(stream))
                            {
                                for (int j = 0; j < imageInSmart.Layers.Length; j++)
                                {
                                    // Looking for Text Layer
                                    var textLayer = imageInSmart.Layers[j] as TextLayer;
                                    if (textLayer != null)
                                    {
                                        // We can use simple UpdateText, but this way give us ability to edit text by portions
                                        // Create multiline text layers and other text and paragraph styling features
                                        // Please be careful. If Smart Object Contents is not PSD, you can not use this way of text editing
                                        // In such case you should use Graphic API: https://docs.aspose.com/psd/net/drawing-images-using-graphics/
                                        var textData = textLayer.TextData;
                                        textData.Items[0].Text = "Best";

                                        // You should change size of text if you want to make image to look fine.
                                        textData.Items[0].Style.FontSize = 170;
                                    }
                                }

                                // It's better to use ReplaceContents. It will automatically rerender Smart Object
                                smart.ReplaceContents(imageInSmart);
                            }
                        }
                    }
                }

                // In this way we are saving changed PSD File
                image.Save(outputFilePath, new PsdOptions(image));
                image.Save(outputPngFilePath, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha });
            }

PSDNET792_1.zip (9.9 MB)

The issues you have found earlier (filed as PSDNET-792) have been fixed in this update.

Hi, I downloaded the latest version Aspose.PSD for .NET 21.2 (Dlls only) and use in my project with net 2.0
Also I use code from above
This files I get after run the code
https://www.dropbox.com/s/z8p2iug6zpaq8yo/output.zip?dl=0
result files looks not good
Is any way to fix it?

@aspose_psd

If you are referring to incorrect blending of more than one Layer Effect, then the concerned ticket PSDNET-789 is still unresolved. We request for your patience and will share the feedback with you once it will be fixed.

Is it possible to achieve this ticket?it takes so much time

@aspose_psd

There are two issues associated with this thread.

PSDNET-792: It has already been fixed and was concerning to exception being thrown on saving PSD with Smart Objects
PSDNET-789: This is is regarding incorrect blending of more than one layer effects as shown in image attached.
image.jpg (142.6 KB)

If there is any thing otherwise, please share with us and we will investigate that as well for you.

I just interesting is it possible to achieve PSDNET-789? maybe it’s not possible task?

@aspose_psd

At the moment it is not possible and we will update you as soon as the issue will be addressed.

Is this task hard for your developers?Why it takes so much time?

@aspose_psd

Actually, there are many things dependent on internal API limitations that are required to be addressed first to fix this issue. We are trying best to meet the requirements and will share the good news with you as soon as it will be addressed.

I spoke with another developer, he said this task can’t be achieve because this is only Photoshop feature
may be I wait for nothing?

@aspose_psd

I have added your comments in issue tracking system and request for your patience till the time the development team share its feedback for blending image requirements.

is any good news?

@aspose_psd

The stroke effect like other effects is really a Photoshop feature but we are trying to make our own realization of these effects.

            string srcFile = "source_789.psd";
            string outputSmartObjectPath = "output789.png";
            string outputFile = "output789.psd";

            using (PsdImage image = (PsdImage)Image.Load(srcFile, new PsdLoadOptions() { LoadEffectsResource = true }))
            {
                var length = image.Layers.Length;
                for (int i = 0; i < length; i++)
                {
                    var smart = image.Layers[i] as SmartObjectLayer;
                    if (smart != null && smart.Name == "__D__")
                    {
                        using (var stream = new MemoryStream(smart.Contents))
                        {
                            stream.Position = 0;
                            using (var imageInSmart = (PsdImage)Image.Load(stream))
                            {
                                for (int j = 0; j < imageInSmart.Layers.Length; j++)

                                {
                                    // Looking for Text Layer
                                    var textLayer = imageInSmart.Layers[j] as TextLayer;
                                    if (textLayer != null)
                                    {
                                        var textData = textLayer.TextData;

                                        textData.Items[0].Text = "Best";
                                        textData.Items[0].Style.FontSize = 170;
                                    }
                                }

                                smart.ReplaceContents(imageInSmart);
                            }
                        }

                        break;
                    }
                }
                // In this way we are saving changed PSD File
                image.Save(outputSmartObjectPath, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha });
                image.Save(outputFile);
            }

Please download the files from [this Drive link] and I will remove that later on.

I use this code with latest dll but it not works
https://www.dropbox.com/s/ddmn9dnykl7k5il/333.zip?dl=0

@aspose_psd

I have used licensed version Aspose.PSD for .NET 21.5 on my end and there is no issue in output using the sample code that I have shared. Can you please try using licensed version on your end.

Archive.zip (5.4 MB)

I don’t have licensed version

@aspose_psd

You can consider availing 30 days trial license in that case. I have used your source files and same sample code above to obtain the correct output.