如何使用一些代码向 tiff 图像添加专色通道?

发布于 2025-01-16 03:36:38 字数 290 浏览 2 评论 0原文

我需要向 tiff 图像添加一个附加通道(使用自定义名称,而不是 alpha)。 我很惊讶这有多困难,因为 tiff-secification 说可以添加自定义通道,并且 PhotoShop 能够做到这一点。 现在我正在寻找一种自动化的方法......

有谁知道现在是否可以使用任何代码或任何框架?

像这样在photoshop中: https://i.sstatic.net/xtOzb.png

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

停滞 2025-01-23 03:36:38

我在网上找到了一些 Photoshop JSX 代码并将其拼凑在一起。我不是编码员,但它对我有用。从 PS 内部作为脚本运行。它将选择所有像素并使选区中的专色通道变为白色。

// 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.");
}

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.");
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文