How do you get the font size and stroke information for a text layer

My psd file has a text layer. I have a stroke effect on the text. I want to get the font size of the text layer, the stroke color and the stroke width. As shown in my screenshot:
1715155305406.png (14.7 KB)

I tried many ways and looked at the api but couldn’t find a suitable way to get the information I needed to use aspose-psd for Java.

Font font = textLayer.getFont();
int size = font.getSize();

The font size returned by the above method is not the same as the one I showed in photoshop and will be the same for multiple text layers of the same psd file.
And how to get the text stroke method, I have not found, please help!

Please check the following API Reference:
Please use TextLayer | Aspose.PSD for Java API Reference

And then multiply it to Transformation matrix in the case it was changed in your file.

Here is example:

    double[] matrix = ((TextLayer)psdImage.getLayers()[layerIndex]).getTransformMatrix();
    double baseFontSize = ((TextLayer)psdImage.getLayers()[layerIndex]).getFont().getSize();
    double fontSize = matrix[0] * baseFontSize;

Thank you very much! The method you provided works, but when the text is not horizontal, it can’t be simply computed using matrix[0] * baseFontSize.
Are there more detailed instructions for using the transformation matrix data? I don’t really understand this part.

Also, how to get the stroke information of the text layer, such as whether there is a stroke, the width of the stroke, and the color of the stroke. thank you.

@Liujinye here is detailed description of this issue butg for the Aspose.PSD for .NET

For the rotated text please use the following formula:

 double sizeInPs =  size * matrix[2] + size * matrix[3];

Transformation matrix contains the following data:
| a b 0|
| c d 0|
| tX tY 0|

a = cos(q)
b = sin(q)
c = –sin(q)
d = cos(q)
tx - Text Position X
ty - Text Position Y

This way of the storing font size is used by default in the PSD Files.

To get the stroke data please use the following code:

        ILayerEffect[] effects = im.getLayers()[index].getBlendingOptions().getEffects();
        for (int i = 0; i < effects.length; i++) {
            if (effects[i] instanceof StrokeEffect) {
                 StrokeEffect effect = (StrokeEffect)effects[i];
            
                 // Here is size of Stroke
                 int size = effect.getSize();
            }
        }

Thanks a lot, this has solved my problem of getting the text size.

I’ve taken your code and adapted it to fit the context of my code, but all the text layers are getting an ILayerEffect array of 0. I tried two versions of the sdk, one is 23.4, the other is the latest 24.4, and I got both empty arrays of ILayerEffect. I’m sure I have two text layers with stroke enabled.
And help me see what the problem is. Please see my screenshot. Thanks!
1715223243745.png (57.5 KB)
1715223243755.png (63.8 KB)

@Liujinye please try to use the following code for file opening:

PsdLoadOptions psdLoadOptions = new PsdLoadOptions();
psdLoadOptions.setLoadEffectsResource(true);
psdLoadOptions.setUseDiskForLoadEffectsResource(true);

PsdImage image = (PsdImage)Image.load("test.psd", psdLoadOptions);
// Here is manipulation with effects.

We can actually get the stroke property value, thank you very much!

1 Like