Skip to main content
Inspiring
July 21, 2016
Answered

Rasterize all text layers?

  • July 21, 2016
  • 1 reply
  • 2743 views

Hi,

Can anyone please point me in the right direction with regards to looping through an open psd file, and rasterizing ALL text layers (no other layers).

I'm not one of these people who expect scripts written for them, so just a point in the right direction would suffice (unless you're feeling very generous).

I'm new to Photoshop scripting and still getting my head around certain syntax.

Thank you all in advance.

This topic has been closed for replies.
Correct answer JJMack

Is this it?

if (!documents.length) { alert('There are no documents open.', 'No Document');}

else {processArtLayers(activeDocument);}

function processArtLayers(obj) {

    for( var i = obj.artLayers.length-1; 0 <= i; i--) { if (obj.artLayers.kind==LayerKind.TEXT){  obj.artLayers.rasterize(RasterizeType.TEXTCONTENTS); } }

    for( var i = obj.layerSets.length-1; 0 <= i; i--) {processArtLayers(obj.layerSets); } // Process Layer Set Layers

}

1 reply

Chuck Uebele
Community Expert
July 21, 2016

You want to write a recursive function that loop though the layers, and if it comes across a group, it runs the function on that group, thus finding all the layers. If your files don't have groups, they you just need to make a simple loop to find the text layers, but using the below code, create a loop and use the DOM or scriptlistener to get code to rasterize the text layer:

#target photoshop

var doc = activeDocument

if(doc.activeLayer.kind = LayerKind.TEXT){

   //put code to rasterize here

    }

Inspiring
July 21, 2016

Thank you Chuck.

I seem to be a little bit lost as to your last statement regarding rasterising the actual text layers.

You code example has now taught me how to loop through layers in order to find text layers, but the rasterising part has bamboozled me - I can find no reference to it anywhere

JJMack
JJMackCorrect answer
Community Expert
July 21, 2016

Is this it?

if (!documents.length) { alert('There are no documents open.', 'No Document');}

else {processArtLayers(activeDocument);}

function processArtLayers(obj) {

    for( var i = obj.artLayers.length-1; 0 <= i; i--) { if (obj.artLayers.kind==LayerKind.TEXT){  obj.artLayers.rasterize(RasterizeType.TEXTCONTENTS); } }

    for( var i = obj.layerSets.length-1; 0 <= i; i--) {processArtLayers(obj.layerSets); } // Process Layer Set Layers

}

JJMack