Skip to main content
dolldivine
Inspiring
August 18, 2020
Answered

Rasterize/Flatten layer transparency quickly

  • August 18, 2020
  • 7 replies
  • 6876 views

For most effects you can just right-click the layer and "Rasterize".

But you can't do this if the only effect is layer transparency.

Let's say you have hundreds of layers, each with a different transparency, and you want to rasterize each one individually this so the pixels are just transparent, and it's not a layer setting.  Is there a faster or better way than making one hundred more new layers, placing each under the old layer, flattening, then re-pasting the layer name?  Surely there must be a better way...

This topic has been closed for replies.
Correct answer dolldivine

UPDATE: in case this helps anyone else, the quickest hack I've found so far is to apply some bogus layer effect (ie. color overlay at 0%), then hold down the Alt key and drag/apply it to all the transparent layers.  Then it's possible to right-click -> rasterize.  This is quicker than creating new layers and flattening.

7 replies

Stephen Marsh
Community Expert
October 5, 2022

The following script works on multiple selected layers. For simplicity and speed, it merges, rather than rasterizes - however, the end result should be the same.

 

/* 
Rasterize selected layers opacity.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/rasterize-flatten-layer-transparency-quickly/m-p/11393469
Stephen Marsh - 5th October 2022, v1.0 
*/

#target photoshop

function main() {

    ///// Process selected layers - from jazz-y /////
    var s2t = stringIDToTypeID;
    (r = new ActionReference()).putProperty(s2t('property'), p = s2t('targetLayersIDs'));
    r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
    var lrs = executeActionGet(r).getList(p),
        sel = new ActionReference();
    for (var i = 0; i < lrs.count; i++) {
        sel.putIdentifier(s2t('layer'), p = lrs.getReference(i).getIdentifier(s2t('layerID')));
        (r = new ActionReference()).putIdentifier(s2t('layer'), p);
        (d = new ActionDescriptor()).putReference(s2t("target"), r);
        executeAction(s2t('select'), d, DialogModes.NO);
        
        /////
        
        var layerName = activeDocument.activeLayer.name;
        layerToGroup();
        activeDocument.activeLayer.merge();
        activeDocument.activeLayer.name = layerName;

        function layerToGroup() {
            var s2t = function (s) {
                return app.stringIDToTypeID(s);
            };
            var descriptor = new ActionDescriptor();
            var reference = new ActionReference();
            var reference2 = new ActionReference();
            reference.putClass(s2t("layerSection"));
            descriptor.putReference(s2t("null"), reference);
            reference2.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
            descriptor.putReference(s2t("from"), reference2);
            executeAction(s2t("make"), descriptor, DialogModes.NO);
        }
    }
}
app.activeDocument.suspendHistory("Rasterize selected layers opacity", "main()");

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

 

 

Edit: This v2 uses layer style and rasterize:

 

/* 
Rasterize selected layers opacity.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/rasterize-flatten-layer-transparency-quickly/m-p/11393469
Stephen Marsh - 5th October 2022, v2.0 
*/

#target photoshop

function main() {

    ///// Process selected layers - from jazz-y /////
    var s2t = stringIDToTypeID;
    (r = new ActionReference()).putProperty(s2t('property'), p = s2t('targetLayersIDs'));
    r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
    var lrs = executeActionGet(r).getList(p),
        sel = new ActionReference();
    for (var i = 0; i < lrs.count; i++) {
        sel.putIdentifier(s2t('layer'), p = lrs.getReference(i).getIdentifier(s2t('layerID')));
        (r = new ActionReference()).putIdentifier(s2t('layer'), p);
        (d = new ActionDescriptor()).putReference(s2t("target"), r);
        executeAction(s2t('select'), d, DialogModes.NO);

        /////

        if (haslayerEffects() === false) {
            addStyle();
            rasterizeLayer();
        } else {
            rasterizeLayer();
        }

        ///// Functions /////

        function haslayerEffects() {
            try {
                var d = new ActionDescriptor();
                var r = new ActionReference();
                r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
                var options = executeActionGet(r);
                return options.hasKey(stringIDToTypeID("layerEffects"))
            } catch (e) {
                alert(e)
            }
        }

        function addStyle() {
            var s2t = function (s) {
                return app.stringIDToTypeID(s);
            };
            var descriptor = new ActionDescriptor();
            var descriptor2 = new ActionDescriptor();
            var descriptor3 = new ActionDescriptor();
            var descriptor4 = new ActionDescriptor();
            var reference = new ActionReference();
            reference.putProperty(s2t("property"), s2t("layerEffects"));
            reference.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
            descriptor.putReference(s2t("null"), reference);
            descriptor2.putUnitDouble(s2t("scale"), s2t("percentUnit"), 200);
            descriptor3.putBoolean(s2t("enabled"), true);
            descriptor3.putBoolean(s2t("present"), true);
            descriptor3.putBoolean(s2t("showInDialog"), true);
            descriptor3.putEnumerated(s2t("mode"), s2t("blendMode"), s2t("overlay"));
            descriptor4.putDouble(s2t("red"), 128); // value
            descriptor4.putDouble(s2t("grain"), 128); // value
            descriptor4.putDouble(s2t("blue"), 128); // value
            descriptor3.putObject(s2t("color"), s2t("RGBColor"), descriptor4);
            descriptor3.putUnitDouble(s2t("opacity"), s2t("percentUnit"), 0); // opacity
            descriptor2.putObject(s2t("solidFill"), s2t("solidFill"), descriptor3);
            descriptor.putObject(s2t("to"), s2t("layerEffects"), descriptor2);
            executeAction(s2t("set"), descriptor, DialogModes.NO);
        }

        function rasterizeLayer() {
            var s2t = function (s) {
                return app.stringIDToTypeID(s);
            };

            var descriptor = new ActionDescriptor();
            var reference = new ActionReference();

            reference.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
            descriptor.putReference(s2t("null"), reference);
            descriptor.putEnumerated(s2t("what"), s2t("rasterizeItem"), s2t("layerStyle"));
            executeAction(s2t("rasterizeLayer"), descriptor, DialogModes.NO);
        }
    }
}
app.activeDocument.suspendHistory("Rasterize selected layers opacity", "main()");

 

dolldivine
Inspiring
October 4, 2022

Well it's 2022 and I ended up back on my thread since I still need this and it still doesn't exist 

Community Expert
October 4, 2022

Select the Layer, press command g (Layer > Group Layers) then press command e (Layer > Merge Down).  This is a little bit faster than the approach of creating a new, empty layer, but the resulting Layer Names (Group 1, Group 2, Group 3) will need a little housekeeping to restore descriptive Layer Names.

 

I'm not sure if this approach as been mentioned...
1. Use File > Export > Layers to Files...

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Browse to a new folder to temporarily hold the individual files.  File Type of PSD or PNG-24 should work well.  Be sure to enable Transparency and disable Trim Layers in the Export Layers to Files dialog box.

 

2. File > Scripts > Load Files Into Stack.  Choose the folder created in step 1.  The padded numbering (0000, 0001, 0002, etc.) of the Export Layers to Files process should allow Photoshop to stack the Layers in the correct order from front to back.

 

Once the resulting layered Photoshop document is saved, the folder containing the layers from step 1 can be deleted or archived.

dolldivine
dolldivineAuthorCorrect answer
Inspiring
August 26, 2020

UPDATE: in case this helps anyone else, the quickest hack I've found so far is to apply some bogus layer effect (ie. color overlay at 0%), then hold down the Alt key and drag/apply it to all the transparent layers.  Then it's possible to right-click -> rasterize.  This is quicker than creating new layers and flattening.

Jeff Arola
Community Expert
August 19, 2020

What exactly are you wanting to happen when you "rasterize" a transparent layer?

 

You can post screenshots if it will help explain.

dolldivine
Inspiring
August 19, 2020

For the "Opacity" layer setting to go from X% (eg. 85%) to 100%, and for the transparency to be permanently applied to the pixels on that layer.  For example, if the transparency was 50%, and you'd rasterize, the opacity setting would reset back to 100%, and all the pixels on the layer would be permanently transparent.

 

This already happens if there's a transparency set AND a blend mode set at the same time, and you rasterize.  I have no idea why they wouldn't have the same thing happen when it's just the transparency that's set.

dolldivine
Inspiring
August 19, 2020

So I guess what I'm saying is, I'm requesting that when you right-click a layer and select "Rasterize", it also includes layers with only transparency applied...

Jeff Arola
Community Expert
August 18, 2020

Try File>Scripts>Flatten All Layer Effects

dolldivine
Inspiring
August 19, 2020

So.. I tried this... and I had to step away from the computer because it took a while.. 15 minutes or more.  Finally I get access again and.. believe it or not, this did NOT rasterize the transparency.  All my "85%" transparency layers are still 85% transparency O_O

Stephen Marsh
Community Expert
August 18, 2020

I'd add a new blank layer above the layer then merge down.

dolldivine
Inspiring
August 19, 2020

Yeah, I guess that saves having to re-paste the layer name.  But making and flattening hundreds of layers just to rasterize transparency is just.. there just has to be a better way..

Stephen Marsh
Community Expert
August 27, 2020

There is a better way, record the steps into an action or script. Automating via action or script is faster. It takes approx 0.06 seconds (according to my JavaScript action timer) for an action to create a new layer above the current layer and merge down). This is approx. the same time as the rasterize command. Either way, automation is the answer to productivity.