零点参考线、缩放选定图层、透明像素裁切
This commit is contained in:
1 parent
58155f32d6
commit
6a800280d4
3 files changed
+175
No files matched your search
@@ -0,0 +1,51 @@
|
|||||||
|
#target photoshop
|
||||||
|
|
||||||
|
/*
|
||||||
|
Create missing guides at the document origin.
|
||||||
|
Existing guides at X=0 or Y=0 are not duplicated.
|
||||||
|
*/
|
||||||
|
|
||||||
|
(function () {
|
||||||
|
if (app.documents.length === 0) {
|
||||||
|
alert("请先打开一个文档。");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
var document = app.activeDocument;
|
||||||
|
var hasVerticalAtZero = false;
|
||||||
|
var hasHorizontalAtZero = false;
|
||||||
|
var tolerance = 0.001;
|
||||||
|
var i;
|
||||||
|
|
||||||
|
for (i = 0; i < document.guides.length; i++) {
|
||||||
|
var guide = document.guides[i];
|
||||||
|
var position = guide.coordinate.as("px");
|
||||||
|
|
||||||
|
if (Math.abs(position) <= tolerance) {
|
||||||
|
if (guide.direction === Direction.VERTICAL) {
|
||||||
|
hasVerticalAtZero = true;
|
||||||
|
} else if (guide.direction === Direction.HORIZONTAL) {
|
||||||
|
hasHorizontalAtZero = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hasVerticalAtZero) {
|
||||||
|
document.guides.add(
|
||||||
|
Direction.VERTICAL,
|
||||||
|
new UnitValue(0, "px")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hasHorizontalAtZero) {
|
||||||
|
document.guides.add(
|
||||||
|
Direction.HORIZONTAL,
|
||||||
|
new UnitValue(0, "px")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
alert("创建参考线失败:\n" + error.message);
|
||||||
|
}
|
||||||
|
}());
|
||||||
|
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
#target photoshop
|
||||||
|
|
||||||
|
/*
|
||||||
|
Uniformly scale the active Photoshop layer.
|
||||||
|
Input range: 0.1 to 1.0
|
||||||
|
Default: 0.5 (50%)
|
||||||
|
*/
|
||||||
|
|
||||||
|
(function () {
|
||||||
|
function showMessage(text) {
|
||||||
|
alert(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
function hasSelectedLayer() {
|
||||||
|
var propertyID = stringIDToTypeID("targetLayersIDs");
|
||||||
|
var reference = new ActionReference();
|
||||||
|
reference.putProperty(stringIDToTypeID("property"), propertyID);
|
||||||
|
reference.putEnumerated(
|
||||||
|
stringIDToTypeID("document"),
|
||||||
|
stringIDToTypeID("ordinal"),
|
||||||
|
stringIDToTypeID("targetEnum")
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
var descriptor = executeActionGet(reference);
|
||||||
|
return descriptor.hasKey(propertyID) &&
|
||||||
|
descriptor.getList(propertyID).count > 0;
|
||||||
|
} catch (error) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (app.documents.length === 0) {
|
||||||
|
showMessage("打开一个文档以使用此脚本。");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hasSelectedLayer()) {
|
||||||
|
showMessage("请先选择一个需要缩放的图层。");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var dialog = new Window("dialog", "缩放选定图层");
|
||||||
|
dialog.orientation = "column";
|
||||||
|
dialog.alignChildren = "fill";
|
||||||
|
|
||||||
|
var inputGroup = dialog.add("group");
|
||||||
|
inputGroup.orientation = "row";
|
||||||
|
inputGroup.add("statictext", undefined, "缩放比例(0.1-1):");
|
||||||
|
var scaleInput = inputGroup.add("edittext", undefined, "0.5");
|
||||||
|
scaleInput.characters = 8;
|
||||||
|
scaleInput.active = true;
|
||||||
|
|
||||||
|
var buttonGroup = dialog.add("group");
|
||||||
|
buttonGroup.alignment = "right";
|
||||||
|
var cancelButton = buttonGroup.add("button", undefined, "Cancel", { name: "cancel" });
|
||||||
|
var okButton = buttonGroup.add("button", undefined, "OK", { name: "ok" });
|
||||||
|
|
||||||
|
var scaleValue = null;
|
||||||
|
|
||||||
|
okButton.onClick = function () {
|
||||||
|
var value = parseFloat(scaleInput.text.replace(",", "."));
|
||||||
|
|
||||||
|
if (isNaN(value) || value < 0.1 || value > 1) {
|
||||||
|
showMessage("Enter a number from 0.1 to 1.");
|
||||||
|
scaleInput.active = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
scaleValue = value;
|
||||||
|
dialog.close(1);
|
||||||
|
};
|
||||||
|
|
||||||
|
cancelButton.onClick = function () {
|
||||||
|
dialog.close(0);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (dialog.show() !== 1 || scaleValue === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
var layer = app.activeDocument.activeLayer;
|
||||||
|
var percent = scaleValue * 100;
|
||||||
|
|
||||||
|
layer.resize(
|
||||||
|
percent,
|
||||||
|
percent,
|
||||||
|
AnchorPosition.MIDDLECENTER
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
showMessage("Scale failed:\n" + error.message);
|
||||||
|
}
|
||||||
|
}());
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
#target photoshop
|
||||||
|
|
||||||
|
/*
|
||||||
|
Trim transparent pixels on all four sides.
|
||||||
|
|
||||||
|
Equivalent Photoshop command:
|
||||||
|
Image > Trim...
|
||||||
|
Based On: Transparent Pixels
|
||||||
|
Trim Away: Top, Bottom, Left, Right
|
||||||
|
*/
|
||||||
|
|
||||||
|
(function () {
|
||||||
|
if (app.documents.length === 0) {
|
||||||
|
alert("没有打开的文档。请打开一个文档后再运行此脚本。");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
app.activeDocument.trim(
|
||||||
|
TrimType.TRANSPARENT,
|
||||||
|
true, // Top
|
||||||
|
true, // Left
|
||||||
|
true, // Bottom
|
||||||
|
true // Right
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
alert("Trim failed:\n" + error.message);
|
||||||
|
}
|
||||||
|
}());
|
||||||
|
|
||||||
Reference in new issue
Block a user