You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Photoshop/Photopea脚本为指定文本图层添加描边

Photoshop Script (JSX) 实现文本图层描边

以下是针对名称为MSG_1的文本图层添加红色3像素描边的脚本:

// 遍历文档图层,定位目标文本图层
var targetLayer = null;
for (var i = 0; i < app.activeDocument.layers.length; i++) {
    var layer = app.activeDocument.layers[i];
    if (layer.name === "MSG_1" && layer.kind === LayerKind.TEXT) {
        targetLayer = layer;
        break;
    }
}

if (targetLayer) {
    // 添加描边样式
    var strokeStyle = targetLayer.layerEffects.addStroke();
    
    // 设置描边颜色为#ff0000(红色)
    strokeStyle.color.rgb.red = 255;
    strokeStyle.color.rgb.green = 0;
    strokeStyle.color.rgb.blue = 0;
    
    // 设置描边大小为3像素
    strokeStyle.size = 3;
    
    // 可选:设置描边位置为外部(默认居中,可按需调整)
    strokeStyle.position = StrokePosition.OUTSIDE;
    
    alert("描边已成功添加到图层 MSG_1");
} else {
    alert("未找到名称为MSG_1的文本图层");
}

使用方式:将代码保存为.jsx格式文件,在Photoshop中通过文件 > 脚本 > 浏览选择该文件运行即可。


Photopea Script 实现文本图层描边

Photopea可通过内置API直接操作图层样式,实现代码如下:

// 定位目标文本图层
var targetLayer = app.activeDocument.getLayerByName("MSG_1");

if (targetLayer && targetLayer.isTextLayer()) {
    // 添加描边效果
    var stroke = targetLayer.addEffect("stroke");
    
    // 设置描边颜色为#ff0000
    stroke.color = new RGBColor(255, 0, 0);
    
    // 设置描边大小为3像素
    stroke.size = 3;
    
    // 可选:设置描边位置为外部(默认居中)
    stroke.position = "outside";
    
    alert("描边已成功添加");
} else {
    alert("未找到目标文本图层");
}

使用方式:打开Photopea后按Shift+F9打开脚本面板,粘贴代码后点击运行按钮即可。

内容的提问来源于stack exchange,提问作者Newbie Boy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 02:22:05