• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Sort Different Background Layers types

Engaged ,
May 01, 2019 May 01, 2019

Copy link to clipboard

Copied

Hello everyone,

I need to do an action based on the content of a background layer.

Sometimes the background is totally white (as a result of creating a new document CTRL+N):

and sometimes the background isn't white (for example if I opened a jpg file)

what is the best way to differ between these two?

(i can do an average color of the layer but there must be a better way)

Thanks

TOPICS
Actions and scripting

Views

594

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
May 01, 2019 May 01, 2019

Copy link to clipboard

Copied

I think the Histogram should provide a useful approach.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
May 01, 2019 May 01, 2019

Copy link to clipboard

Copied

#target photoshop 

if(documents.length){

var doc = activeDocument 

app.preferences.rulerUnits = Units.PIXELS; 

var h = doc.histogram 

var empty = false 

for (i=0;i<h.length;i++){ 

    if(h == Number(doc.width*doc.height)){

        empty = true;

        break;

        } 

    }  

if (empty){

    alert("White Document");

   // doAction("ActionName","ActionSet");

    }else{

        alert("Not White Document");

        //doAction("ActionName","ActionSet");

        }

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 01, 2019 May 01, 2019

Copy link to clipboard

Copied

And if you should be bored:

What about newly created documents that were not created with white as »Background Contents«?

If the task is determining a newly created document I wonder if other approaches (History maybe) would not make sense, too.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
May 01, 2019 May 01, 2019

Copy link to clipboard

Copied

Very true!

It depends on how deep it should go, this might surfice?

#target photoshop 

if(documents.length) testColour();

function testColour(){

var doc = activeDocument 

app.preferences.rulerUnits = Units.PIXELS; 

var pixels = Number(doc.width*doc.height);

var h = doc.histogram 

if(h[0] == pixels){

alert("Solid Black Document");

// doAction("ActionName","ActionSet");

return;

}

if(h[255] == pixels ){

    alert("Solid White/Transparent Document");

// doAction("ActionName","ActionSet");

return;

}

var empty = false 

for (i=0;i<h.length;i++){ 

    if(h == Number(doc.width*doc.height)){

        empty = true;

        break;

        } 

    }  

if (empty){

    alert("Solid Colour Document");

   // doAction("ActionName","ActionSet");

    }else{

        alert("Not Solid Colour Document");

        //doAction("ActionName","ActionSet");

        }

};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 01, 2019 May 01, 2019

Copy link to clipboard

Copied

Although not directly applicable to this situation, it is worth mentioning this article with related code:

Photoshop Script – Determine Layer Kind

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 01, 2019 May 01, 2019

Copy link to clipboard

Copied

LATEST

AG_Ps_100 , maybe you could give more context.

What is the ultimate goal here and how does it fit in your workflow?

Because I think creating a new document could be linked to a Script or Action via Script Events Manager anyhow.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines