Aspose.psd saving issue

Can you directly edit the PSB file for the smart object layer? Rewrite the text layer content or replace the image without replacing the PSB. If so, could you please provide a code? Thank you

@vincent2024 please check the following example, but pleas not that we fix this issue only Aspose.PSD 24.2 (PSDNET-1642 Aspose.PSD for .NET 24.2 - Release Notes|Documentation) :

string inputFile ="source.psd";
string output2 = "output.png";

PsdLoadOptions psdLoadOptions = new PsdLoadOptions();
psdLoadOptions.LoadEffectsResource = true;

using (PsdImage psdImage = (PsdImage)Image.Load(inputFile, psdLoadOptions))
{
    SmartObjectLayer smartObject = (SmartObjectLayer)psdImage.Layers[1];

    using (PsdImage smartObjectImage = (PsdImage)smartObject.LoadContents(psdLoadOptions))
    {
        smartObject.ReplaceContents(smartObjectImage);
    }

    psdImage.Save(output2, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha });
}

What is the reason why the font is lost when I set the specified font in PSB and replace it with an updated one in PSD

@vincent2024 could you please provide input file and code to reproduce this.

        var warpLoadOptions = new PsdLoadOptions() { LoadEffectsResource = true, ReadOnlyMode = false, UseDiskForLoadEffectsResource = true };
        using (PsdImage image = (PsdImage)PsdImage.Load(psdPath, warpLoadOptions)) //warpLoadOptions
        {

            foreach (var layer in image.Layers)
                if (string.Equals(layer.DisplayName, "test", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (layer is SmartObjectLayer smartObjectLayer)
                    {
                        Console.WriteLine("替换 -- >  " + layer.DisplayName);
                        smartObjectLayer.ReplaceContents(@"C:\Users\Lt\Desktop\test\test.psb");
                        // smartObjectLayer.SmartObjectProvider.UpdateAllModifiedContent();
                        //smart.ReplaceContents(imageInSmart); //更新图层
                    }
                }
            {

test.7z (18.9 KB)

The updated PSD file does not change the font and is invalid

ok_error.7z (84.9 KB)

The running effect is shown in the figure, one is correct and the other is incorrect

I used the following code:

        string sourceFile = @"test.psd";
        string replaceFile = @"test.psb";
        string outputFile = @"output.psd";

        var warpLoadOptions = new PsdLoadOptions() { LoadEffectsResource = true, ReadOnlyMode = false, UseDiskForLoadEffectsResource = true };
        using (PsdImage image = (PsdImage)PsdImage.Load(sourceFile, warpLoadOptions)) //warpLoadOptions
        {

            foreach (var layer in image.Layers)
            {
                if (string.Equals(layer.DisplayName, "test", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (layer is SmartObjectLayer smartObjectLayer)
                    {
                        Console.WriteLine("替换 -- >  " + layer.DisplayName);
                        smartObjectLayer.ReplaceContents(replaceFile);
                        smartObjectLayer.UpdateModifiedContent();
                    }
                }
            }

            image.Save(outputFile);

        }
    }

And get the following result:
output.png (2.6 KB)

The text is cropped on the bottom. It because I have not [KaiTi] font installed. Could you please clarify if you have installed KaiTi font? If the font is not installed, both Photoshop and Aspose.PSD try to replace font, that can lead to the visual artifacts because of the different base font size and other font properties.

[KaiTi] I installed it on my computer, but the font was lost after replacing aspose

@vincent2024 I can not reproduce this issue in Aspose.PSD 24.4 with installed KaiTi font. Could you please clarify the following parameters of you Aspose.PSD config:

  1. Operating System (including architecture like 32 bit, x64 or ARM)
  2. Version of Aspose.PSD (23.10, 23.4, etc)
  3. Framework version of Aspose.PSD. There are .NET 2.0, .NET 3.5, .NET 4.0. NetStandard, .NET 5, .NET 6, and . NET 7. Different Aspose.PSD builds uses different Drawing Libraries.

Could you please additionaly specify expected result. My result of the provided code with installed KaiTi font is attached below:
output.zip (11.5 KB)

The operating system I am using is Windows 10 22H2 X64 version
Aspose PSD version 22.9.0.0 Replacing PSB file font in PSD with NET 4.0 is invalid. If this font is already installed on the computer and PSB is opened separately, it is normal. Replacing it will be invalid

@vincent2024 please try Aspose.PSD 24.4. The issue with font replacing in Smart Object was fixed only in 24.2.

I’m sorry, I don’t have a 24.2 license. Can I apply for this version of the trial as an individual? If so, what certifications are needed to apply for it

@vincent2024 I recommend firstly check if the result of 24.2 is suitable for your tasks. You can obtain temporary license on Temporary License - Purchase - aspose.com
Also, Aspose offers discount for the renewing of license. I can mention sales team in this post.
Version 22.9 is one of the first versions where the SmartObject support was added.

For the 22.9 You can try additionally to set the new size of smart object as in code below but it doesn’t fix the issue with missed font. To avoid font lost you can try replace SmartObject with the Regular Layer.

using (PsdImage image = (PsdImage)PsdImage.Load(sourceFile, warpLoadOptions)) 
{
   foreach (var layer in image.Layers)
   {
     if (string.Equals(layer.DisplayName, "test", StringComparison.InvariantCultureIgnoreCase))
     {
        if (layer is SmartObjectLayer smartObjectLayer)
        {
            Console.WriteLine("替换 -- >  " + layer.DisplayName);
            using (PsdImage replacement = (PsdImage)PsdImage.Load(replaceFile, warpLoadOptions))
            {
                smartObjectLayer.Right = smartObjectLayer.Left + replacement.Width;
                smartObjectLayer.Bottom = smartObjectLayer.Top + replacement.Height;
                smartObjectLayer.ReplaceContents(replacement);
                
                smartObjectLayer.UpdateModifiedContent();
            }
        }
    }
}

image.Save(outputFile);

}

I used code to set the font and modify the text content in the PSB. The saved PSB content is normal, but the font part in Photoshop shows that the font was not found, and in the font display part, it is garbled. I used Aspose. psd 23.7.0.0, and the following part is the execution code

textData.Items[0].Text = “hello”;

textData.Items[0].Style.FontName = “创艺简行楷”;

textData.UpdateLayerData();

Image Save (outputFile);
999990000.jpg (40.5 KB)

@vincent2024 could you please provide whole code snippet and input data to reproduce this. We need to test this on the current version

       string sourceFile = @"test.psb";
        string outputFile = @"output.psb";
    public bool UpdatePsd(string sourceFile, string outputFile) 
    {
        PsdLoadOptions psdLoadOptions = new PsdLoadOptions();
        psdLoadOptions.LoadEffectsResource = true;
        var warpLoadOptions = new PsdLoadOptions() { LoadEffectsResource = true, ReadOnlyMode = false, UseDiskForLoadEffectsResource = true };
        using (PsdImage image = (PsdImage)PsdImage.Load(sourceFile, warpLoadOptions)) 
        {
            var length = image.Layers.Length;
            for (int i = 0; i < length; i++)
            {
                var layername = image.Layers[i].DisplayName;

                if (layername == "test1")
                {
                    var textLayer = image.Layers[i] as TextLayer;
                    var textData = textLayer.TextData;
                    textData.Items[0].Text = "hello";
                    textData.Items[0].Style.FontName = "创艺简行楷"; 
                    textData.UpdateLayerData();
                }                  
            }
            image.Save(outputFile);
        }

    }               

demo2.7z (2.5 MB)

My implementation code attachment is the tested PSB and font

@vincent2024 thank you. I’ll check and then text you back.

Okay, thank you for your hard work

@vincent2024 after the investigation, Aspose.PSD Team found the issue. Team will try deliver this fix in 24.5

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PSDNET-2033

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.