Copy link to clipboard
Copied
Hello.
Please help me create a script that removes empty alpha channels.
That is, the ones that have a solid color 0 0 0.
That is, I select the alpha channel and if it is empty 0 0 0 0 by RGB, it is deleted.
If not, nothing happens.
I'm not good at scripting, so I'm asking for help.
Thank you very much.
@alinaj84027284 wrote:
I'm not good at scripting, so I'm asking for help.
Thank you very much.
@alinaj84027284 – Here is the code recommended by @jazz-y based on the original code from @c.pfaffenbichler
// 2022, use it at your own risk;
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
var theChannels = myDocument.channels;
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var theTotal = Number(myDocument.w
...
Copy link to clipboard
Copied
@jazz-y @Stephen_A_Marsh @c.pfaffenbichler @r-bin @Kukurykus maybe can help you with that task.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
@alinaj84027284 wrote:
I'm not good at scripting, so I'm asking for help.
Thank you very much.
@alinaj84027284 – Here is the code recommended by @jazz-y based on the original code from @c.pfaffenbichler
// 2022, use it at your own risk;
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
var theChannels = myDocument.channels;
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var theTotal = Number(myDocument.width) * Number(myDocument.height);
for (var m = theChannels.length - 1; m >= 0; m--) {
var thisChannel = theChannels[m];
if (thisChannel.visible = true) {
var theHisto = thisChannel.histogram;
// 0 or black
if (theHisto[0] == theTotal) {
thisChannel.visible = false;
thisChannel.remove();
} else {
thisChannel.visible = true;
}
}
}
app.preferences.rulerUnits = originalRulerUnits;
}
Copy link to clipboard
Copied
Thank you so much!
This is just what is needed.
Is it possible to make the script work not on all the alpha channels, but only on the selected one?
Copy link to clipboard
Copied
The following code simply removes selected channels, whether they are black or white:
// Remove selected channels
// based on code from c.pfaffenbichler
if (app.documents.length > 0) {
var doc = activeDocument;
var chanArray = doc.activeChannels;
for (var i = 0; i < chanArray.length; i++) {
chanArray[i].remove();
}
}
Copy link to clipboard
Copied
// 2022, use it at your own risk;
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
var theChannels = myDocument.activeChannels;
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var theTotal = Number(myDocument.width) * Number(myDocument.height);
for (var m = theChannels.length - 1; m >= 0; m--) {
var thisChannel = theChannels[m];
if (thisChannel.visible = true) {
var theHisto = thisChannel.histogram;
// 255 or black
if (theHisto[255] == theTotal) {
thisChannel.visible = false;
thisChannel.remove();
} else {
thisChannel.visible = true;
}
}
}
app.preferences.rulerUnits = originalRulerUnits;
}
Copy link to clipboard
Copied
@c.pfaffenbichler – I think that is what @alinaj84027284 is looking for... I think that you forgot to change to:
// 0 or black
if (theHisto[0] == theTotal)
To only remove selected black channels while retaining selected white channels.
Copy link to clipboard
Copied
Ah, sorry, not paying sufficient attention …