Layer effects like Bevel & Emboss already existing on Smart Objects

Hello. I thought there was support for using the effects inside the layer styles feature of Photoshop such as Bevel & Emboss and Color Overlay which are already existing on Smart Objects.
However after testing a Photoshop file with smart objects which have such effects, seems like they are not being rendered.
(It’s a group with a nested group and finally the smart object layer, this way multiple effects can be used that all blend with each other)

@VasilyHall

Hello,

Could you please provide the PSD file and the code that is used for the opening and manipulation?

Thank you.

0400-10BK_B_FR_6901–null.zip (3.4 MB)

Here is the code:

private string CreateTempPsd (string sourceArtPath)
{
  string tempPsdPath = Path.GetFullPath("TEMP.psd", OUTPUT_DIR);
  Bitmap img = new Bitmap(sourceArtPath);
  var imageHeight = img.Height;
  var imageWidth = img.Width;

using (var image = new PsdImage(imageWidth, imageHeight))
{
	using (var stream = new FileStream(sourceArtPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
	{
		Layer? layer = null;
		try
		{
			layer = new Layer(stream);
			image.AddLayer(layer);
		}
		catch (Exception e)
		{
			if (layer != null)
			{
				layer.Dispose();
			}
			throw new Exception(e.Message);
		}
	}
	image.Save(tempPsdPath);
}
return tempPsdPath;
}

// In a main method:
// https://forum.aspose.com/t/working-with-smart-objects/222153
using (PsdImage image = (PsdImage)Aspose.PSD.Image.Load(completeTemplatePath, new 
PsdLoadOptions() { LoadEffectsResource = true }))
{
List<Layer> layersOfInterest = new List<Layer>();

for (int i = 0; i < image.Layers.Length; i++)
{
	var layer = image.Layers[i];
	if (layer is SmartObjectLayer)
	{
		layersOfInterest.Add(layer);
	}
	int counter = 0;
	if (layer is LayerGroup)
	{
		Layer finalLayer = layer;
		while (finalLayer is LayerGroup && (finalLayer as LayerGroup)!.Layers.Length > 0 && counter < 1000)
		{
			finalLayer = (finalLayer as LayerGroup)!.Layers[0]; // * First non-group layer in a layer group.
			counter++;
		}
		if (finalLayer is SmartObjectLayer)
		{
			layersOfInterest.Add(finalLayer);
		}
	}
}

layersOfInterest.ForEach(layer =>
{
	if (layer is SmartObjectLayer)
	{
		SmartObjectLayer smartObjectLayer = (layer as SmartObjectLayer)!;
		string? foundInstructionArtForLayer;
		imageMapMockupInput.LayerNameArtDictionary.TryGetValue(layer.DisplayName, out foundInstructionArtForLayer);
		if (foundInstructionArtForLayer != null)
		{
			string artFilePath = Path.GetFullPath(foundInstructionArtForLayer, UPLOADS_DIR);
			FileInfo fileInfo = new FileInfo(artFilePath);
			if (!fileInfo.Exists)
			{
				throw new Exception($"File was not found at: {artFilePath}");
			}

			string tempPath = CreateTempPsd(artFilePath); // This is only way I could get image to load: make a PSD file and add a PNG image as layer, then replace S.O. with the PSD.

			using (var img = Aspose.PSD.Image.Load(tempPath))
			{
				(layer as SmartObjectLayer)!.ReplaceContents(img);
				(layer as SmartObjectLayer)!.UpdateModifiedContent();
			}

		}
	}
});

//image.SmartObjectProvider.UpdateAllModifiedContent();

string outPath = "root/directory/some-path.png";
image.Save(outPath, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha });

}

Hello,

Provided code can no de compiled because of imageMapMockupInput. Could you please provide the full source code.

Anyway, I have some quick answers before I get full source code:

  1. To render Layer Effects you you should Load PSD Image with the following code(In some snippets you use this property):

    var psdOptions = new PsdLoadOptions() { LoadEffectsResource = true };
    using (var img = Aspose.PSD.Image.Load(tempPath, psdOptions))
    {

    }

  2. Aspose.PSD supports Stroke Effect but doesn’t support Bevel & Emboss. Support will be added later. You can track this issue by the following ids: PSDNET-506, PSDNET-263

  3. Layer Effects in the Smart Object can not be rendered. Ability to pass LoadEffectsResource = true property in Smart Object will be added soon. You can track this issue by the id PSDNET-834.

Thank you.

Ok it’s good to know it will be in the works. I think Color Overlay effect is also working.
The source code for the image mockup input is:

	public class ImageMapMockupInput
{
	public Dictionary<string, string> LayerNameArtDictionary { get; set; } = new Dictionary<string, string>();
	public string? TemplatePath { get; set; }
	public string? OutputName { get; set; }
}