ps工具新增
This commit is contained in:
1 parent
0a1d36d276
commit
fd5a19997e
3 files changed
+2320
No files matched your search
@@ -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);
|
||||
}
|
||||
}());
|
||||
Reference in new issue
Block a user