2

I have designed a website template in Photoshop CC2014 and after making this I have to upload it on a server for my client, but before this I want to delete all images (pixel layers) from .psd files. There are 80+ PSDs so can anyone help me in deleting image (pixel layers) from PSDs, Excluding Background Layer?

This would be great if you can give me action or script.

I know doing pixel filter can help but this is a very slow process.

Layers I need to delete

  • Just the be clear, you want to delete all normal pixel layers (anything that isn't a shape, color, adjustment, background etc)? – Cai Aug 12 '16 at 8:06
  • Yes you're right. I just wanted to delete All Normal Pixel Layers. – Ali Aug 12 '16 at 8:11
  • Isn't the "grid" layer a normal layer too? – Cai Aug 12 '16 at 8:21
  • Yes Mistakenly forgot to highlight. – Ali Aug 12 '16 at 8:26
  • Ok no problem, just making sure. Should be easy enough to script – Cai Aug 12 '16 at 8:30
3

This script will loop through all your layers and groups and delete any normal (pixel) layers. It will record the deletions in the history (as a single history state, thanks Joonas) but PLEASE save before using this and test it thoroughly as I've only done limited testing.

var doc = app.activeDocument;
doc.suspendHistory("Remove Normal Layers", "deletePixelLayers( doc )");

function deletePixelLayers(target)
{
    try{
        var layers = target.layers;
        for (var i = 0; i < layers.length; i++)
        {
            var curLayer = layers[i];
            var visible = curLayer.visible; // remember visibility
            curLayer.allLocked = false; // unlock layer

            // Layer is a group
            if ("LayerSet" == curLayer.typename) {
                deletePixelLayers(curLayer);
            }

            // Layer is a NORMAL (Pixel) Layers
            if (LayerKind.NORMAL == curLayer.kind
                && !curLayer.isBackgroundLayer) {

                curLayer.remove(); // Delete the layer
                --i;
            };

            // restore layer visibility
            if (curLayer) curLayer.visible = visible;
        };
    }catch(e){
        ; // do nothing
    }
};
deletePixelLayers(doc);
  • Since you already wrapped it in a function and all, it's pretty easy to use sustendHistory to write only one history state. Like this. I didn't edit it in the answer cause I can't test it right now. – Joonas Aug 12 '16 at 11:09
  • Good point @Joonas edited it in, works fine. – Cai Aug 12 '16 at 11:18
  • Thanks for sharing but its not working. Error: The Command "Delete" is not currently available. – Ali Aug 12 '16 at 11:35
  • Do you have locked layers or hidden layers? That may be it, I'm not sure – Cai Aug 12 '16 at 11:37
  • Yes few layer are hidden. does this affect the code? – Ali Aug 12 '16 at 11:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.