Skip to main content
bashamer
Participant
September 8, 2015
Answered

how do I create text with an outline, I can't seem to get my selection right.

  • September 8, 2015
  • 2 replies
  • 1681 views

I'm trying to add text with an outline to an image;

The text is showing up fine and has it's own layer

When I make the layer active and do SelectAll() and then add a stroke on the selection I get a big ole box around my image.

I realize that this is likely a simple fix, but my google foo has failed me so far.

Thank you for your help

    var artLayerRef = docRef.artLayers.add();

    artLayerRef.kind = LayerKind.TEXT;

    artLayerRef.name = "Text";

    // Set the contents of the text layer.

    var textItemRef = artLayerRef.textItem;

    textItemRef.size = 25;

    textItemRef.contents = "wubwub";

    textItemRef.position = new Array(

        50,

        50);

    //textItemRef.rasterize(RasterizeType.TEXTCONTENTS);

    docRef.activeLayer = docRef.layers["Text"];

    docRef.selection.selectAll();

    //draw the stroke

    var strokeLayerRef = docRef.artLayers.add();

    strokeLayerRef.kind = LayerKind.NORMAL;

    strokeLayerRef.name = "Stroke";

    var strokeColor= new SolidColor();

    strokeColor.rgb.red = 255;

    strokeColor.rgb.blue = 0;

    strokeColor.rgb.green = 0;

    docRef.selection.stroke(

        strokeColor,

        15,

        StrokeLocation.CENTER); // OUTSIDE / INSIDE

This topic has been closed for replies.
Correct answer Chuck Uebele

If you want to make a selection of just the text, use scriptlistener and ctrl-click on the text's layer's icon to make the selection. Then you can use the code generated to use for your stroke. Or you can use the scriptlistener and create a layer style stroke.

#target photoshop

var idsetd = charIDToTypeID( "setd" );

    var desc6 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref1 = new ActionReference();

        var idChnl = charIDToTypeID( "Chnl" );

        var idfsel = charIDToTypeID( "fsel" );

        ref1.putProperty( idChnl, idfsel );

    desc6.putReference( idnull, ref1 );

    var idT = charIDToTypeID( "T   " );

        var ref2 = new ActionReference();

        var idChnl = charIDToTypeID( "Chnl" );

        var idChnl = charIDToTypeID( "Chnl" );

        var idTrsp = charIDToTypeID( "Trsp" );

        ref2.putEnumerated( idChnl, idChnl, idTrsp );

    desc6.putReference( idT, ref2 );

executeAction( idsetd, desc6, DialogModes.NO );

2 replies

bashamer
bashamerAuthor
Participant
September 14, 2015

oh god, this is the missing link I have been searching for. I have been trying to write things based on the api documentation and it was hell.

I never assumed this damn tool existed

thank you guy so much

Chuck Uebele
Community Expert
Community Expert
September 15, 2015

Glad it helped. Some things you just can't do with the DOM and have to use Action Manager code and scriptlistener.

Chuck Uebele
Community Expert
Chuck UebeleCommunity ExpertCorrect answer
Community Expert
September 13, 2015

If you want to make a selection of just the text, use scriptlistener and ctrl-click on the text's layer's icon to make the selection. Then you can use the code generated to use for your stroke. Or you can use the scriptlistener and create a layer style stroke.

#target photoshop

var idsetd = charIDToTypeID( "setd" );

    var desc6 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref1 = new ActionReference();

        var idChnl = charIDToTypeID( "Chnl" );

        var idfsel = charIDToTypeID( "fsel" );

        ref1.putProperty( idChnl, idfsel );

    desc6.putReference( idnull, ref1 );

    var idT = charIDToTypeID( "T   " );

        var ref2 = new ActionReference();

        var idChnl = charIDToTypeID( "Chnl" );

        var idChnl = charIDToTypeID( "Chnl" );

        var idTrsp = charIDToTypeID( "Trsp" );

        ref2.putEnumerated( idChnl, idChnl, idTrsp );

    desc6.putReference( idT, ref2 );

executeAction( idsetd, desc6, DialogModes.NO );

c.pfaffenbichler
Community Expert
Community Expert
September 13, 2015

Or you can use the scriptlistener and create a layer style stroke.

That would seem to be the more efficient approach for the task.