189 lines
5.9 KiB
JavaScript
189 lines
5.9 KiB
JavaScript
创建并处理文本图层();
|
||
|
||
|
||
function 创建并处理文本图层() {
|
||
// 新建图层
|
||
var textLayer = activeDocument.artLayers.add();
|
||
|
||
// 将新建图层变成文本图层
|
||
textLayer.kind = LayerKind.TEXT;
|
||
|
||
// 将文本内容改为当前文档name
|
||
textLayer.textItem.contents = activeDocument.name;
|
||
|
||
// 字体大小固定值
|
||
var 固定字体大小 = 30; // 例如,30像素
|
||
textLayer.textItem.size = 固定字体大小;
|
||
|
||
// 文字字体固定值
|
||
textLayer.textItem.font = "微软雅黑";
|
||
|
||
// 计算并调整文本位置
|
||
var x = activeDocument.width - textLayer.bounds[2];
|
||
var y = textLayer.bounds[1];
|
||
textLayer.translate(x, -y);
|
||
|
||
// 偏移
|
||
textLayer.translate(UnitValue("-1cm"), UnitValue("+0.5cm"));
|
||
|
||
// 复制并栅格化图层
|
||
var copyLayer = textLayer.duplicate();
|
||
copyLayer.rasterize(RasterizeType.ENTIRELAYER);
|
||
|
||
// 设置固定颜色值
|
||
var 固定颜色 = new SolidColor();
|
||
固定颜色.rgb.red = 255; // 红色分量
|
||
固定颜色.rgb.green = 255; // 绿色分量
|
||
固定颜色.rgb.blue = 255; // 蓝色分量
|
||
|
||
activeDocument.activeLayer = copyLayer;
|
||
activeDocument.selection.fill(固定颜色, ColorBlendMode.NORMAL, 100, true);
|
||
|
||
// 白边
|
||
activeDocument.activeLayer.applyMinimum(10);
|
||
后移一层()
|
||
向上选择()
|
||
向下合并()
|
||
名称更改字体()
|
||
缩小字体图层至文档一半()
|
||
多选背景()
|
||
底对齐()
|
||
水平居中对齐()
|
||
}
|
||
|
||
// 调用函数
|
||
|
||
|
||
|
||
|
||
|
||
function 后移一层() //
|
||
{
|
||
|
||
var d = new ActionDescriptor();
|
||
var r = new ActionReference();
|
||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||
d.putReference(stringIDToTypeID("null"), r);
|
||
var r1 = new ActionReference();
|
||
r1.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("previous"));
|
||
d.putReference(stringIDToTypeID("to"), r1);
|
||
executeAction(stringIDToTypeID("move"), d, DialogModes.NO);
|
||
|
||
}
|
||
|
||
function 向上选择() //
|
||
{
|
||
|
||
var d = new ActionDescriptor();
|
||
var r = new ActionReference();
|
||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("forwardEnum"));
|
||
d.putReference(stringIDToTypeID("null"), r);
|
||
d.putBoolean(stringIDToTypeID("makeVisible"), false);
|
||
var list = new ActionList();
|
||
list.putInteger(19);
|
||
d.putList(stringIDToTypeID("layerID"), list);
|
||
executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
|
||
|
||
}
|
||
function 向下合并() //向下合并
|
||
{
|
||
|
||
var d = new ActionDescriptor();
|
||
executeAction(stringIDToTypeID("mergeLayersNew"), d, DialogModes.NO);
|
||
|
||
}
|
||
|
||
|
||
function 名称更改字体() //名称更改
|
||
{
|
||
|
||
var d = new ActionDescriptor();
|
||
var r = new ActionReference();
|
||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||
d.putReference(stringIDToTypeID("null"), r);
|
||
var d1 = new ActionDescriptor();
|
||
d1.putString(stringIDToTypeID("name"), "字体");
|
||
d.putObject(stringIDToTypeID("to"), stringIDToTypeID("layer"), d1);
|
||
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
|
||
|
||
}
|
||
|
||
|
||
|
||
function 缩小字体图层至文档一半() {
|
||
var 文档 = app.activeDocument;
|
||
var 字体图层 = null;
|
||
|
||
// 遍历文档中的图层以找到名为"字体"的图层
|
||
for (var i = 0; i < 文档.artLayers.length; i++) {
|
||
if (文档.artLayers[i].name === "字体") {
|
||
字体图层 = 文档.artLayers[i];
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (字体图层 !== null) {
|
||
// 获取文档的宽度的一半
|
||
var 目标宽度 = 文档.width / 2;
|
||
|
||
// 获取图层的当前宽度
|
||
var 图层宽度 = 字体图层.bounds[2] - 字体图层.bounds[0];
|
||
|
||
// 计算缩放比例
|
||
var 缩放比例 = 目标宽度 / 图层宽度 * 100;
|
||
|
||
// 缩放图层
|
||
字体图层.resize(缩放比例, 缩放比例, AnchorPosition.MIDDLECENTER);
|
||
} else {
|
||
alert("未找到名为'字体'的图层");
|
||
}
|
||
}
|
||
|
||
|
||
function 多选背景() //自由变换
|
||
{
|
||
|
||
var d = new ActionDescriptor();
|
||
var r = new ActionReference();
|
||
r.putName(stringIDToTypeID("layer"), "背景");
|
||
d.putReference(stringIDToTypeID("null"), r);
|
||
d.putEnumerated(stringIDToTypeID("selectionModifier"), stringIDToTypeID("selectionModifierType"), stringIDToTypeID("addToSelection"));
|
||
d.putBoolean(stringIDToTypeID("makeVisible"), false);
|
||
var list = new ActionList();
|
||
list.putInteger(1);
|
||
list.putInteger(13);
|
||
d.putList(stringIDToTypeID("layerID"), list);
|
||
executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
function 底对齐() //底对齐
|
||
{
|
||
|
||
var d = new ActionDescriptor();
|
||
var r = new ActionReference();
|
||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||
d.putReference(stringIDToTypeID("null"), r);
|
||
d.putEnumerated(stringIDToTypeID("using"), stringIDToTypeID("alignDistributeSelector"), stringIDToTypeID("ADSBottoms"));
|
||
d.putBoolean(stringIDToTypeID("alignToCanvas"), false);
|
||
executeAction(stringIDToTypeID("align"), d, DialogModes.NO);
|
||
|
||
}
|
||
|
||
|
||
|
||
function 水平居中对齐() //水平居中对齐
|
||
{
|
||
|
||
var d = new ActionDescriptor();
|
||
var r = new ActionReference();
|
||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||
d.putReference(stringIDToTypeID("null"), r);
|
||
d.putEnumerated(stringIDToTypeID("using"), stringIDToTypeID("alignDistributeSelector"), stringIDToTypeID("ADSCentersH"));
|
||
d.putBoolean(stringIDToTypeID("alignToCanvas"), false);
|
||
executeAction(stringIDToTypeID("align"), d, DialogModes.NO);
|
||
|
||
} |