Reputation: 1
I need to add an additional channel (with a custom name, not alpha) to a tiff image. I'm surprised how difficult this is, because the tiff-secification says it is possible to add custom channels and PhotoShop is able to do it. Now I'm looking for a way to automate it....
Does anyone know whether it is now possible with any code or any framework?
like this in photoshop: https://i.sstatic.net/xtOzb.png
Upvotes: 0
Views: 576
Reputation: 21
I found some Photoshop JSX code on the web and cobbled it together. I am no coder but it works for me. Run as a script from inside PS. It will select all pixels and make a spot channel white from the selection.
// Define the necessary Photoshop Action IDs
var idSetDescriptor = charIDToTypeID("setd");
var desc = new ActionDescriptor();
var idNull = charIDToTypeID("null");
var refNull = new ActionReference();
var idChannel = charIDToTypeID("Chnl");
var idFront = charIDToTypeID("fsel");
refNull.putProperty(idChannel, idFront);
desc.putReference(idNull, refNull);
var idTarget = charIDToTypeID("T ");
var refTarget = new ActionReference();
var idChannel = charIDToTypeID("Chnl");
var idChannel = charIDToTypeID("Chnl");
var idTransparency = charIDToTypeID("Trsp");
refTarget.putEnumerated(idChannel, idChannel, idTransparency);
desc.putReference(idTarget, refTarget);
// Execute the action
executeAction(idSetDescriptor, desc, DialogModes.NO);
// Ensure there's an active selection
if (app.activeDocument.selection.bounds) {
// Create a new spot channel based on the current selection
var idMk = charIDToTypeID("Mk ");
var desc = new ActionDescriptor();
var idNw = charIDToTypeID("Nw ");
var spotChannelDesc = new ActionDescriptor();
// Set the name of the Spot Channel
var idNm = charIDToTypeID("Nm ");
spotChannelDesc.putString(idNm, "white");
// Define the color for the Spot Channel (White in this case)
var idClr = charIDToTypeID("Clr ");
var colorDesc = new ActionDescriptor();
var idH = charIDToTypeID("H ");
var idAng = charIDToTypeID("#Ang");
colorDesc.putUnitDouble(idH, idAng, 0); // Hue (not needed for white)
var idStrt = charIDToTypeID("Strt");
colorDesc.putDouble(idStrt, 0); // Saturation
var idBrgh = charIDToTypeID("Brgh");
colorDesc.putDouble(idBrgh, 100); // Brightness
var idHSBC = charIDToTypeID("HSBC");
spotChannelDesc.putObject(idClr, idHSBC, colorDesc);
// Set opacity to 100%
var idOpct = charIDToTypeID("Opct");
spotChannelDesc.putInteger(idOpct, 100);
// Create the Spot Channel
var idSCch = charIDToTypeID("SCch");
desc.putObject(idNw, idSCch, spotChannelDesc);
// Execute the action
executeAction(idMk, desc, DialogModes.NO);
// Fill the selection with the spot color
var idFill = charIDToTypeID("Fl ");
var fillDesc = new ActionDescriptor();
var idnull = charIDToTypeID("null");
var ref = new ActionReference();
ref.putName(charIDToTypeID("Chnl"), "Spot Channel");
fillDesc.putReference(idnull, ref);
var idT = charIDToTypeID("T ");
var fillColor = new ActionDescriptor();
var idClr = charIDToTypeID("Clr ");
var colorDesc = new ActionDescriptor();
colorDesc.putDouble(charIDToTypeID("Rd "), 255); // Red
colorDesc.putDouble(charIDToTypeID("Grn "), 255); // Green
colorDesc.putDouble(charIDToTypeID("Bl "), 255); // Blue
fillColor.putObject(idClr, charIDToTypeID("RGBC"), colorDesc);
fillDesc.putObject(idT, charIDToTypeID("Clr "), fillColor);
} else {
alert("No selection found. Please make a selection first.");
}
Upvotes: 1