From 6a800280d4c305f1c2e2434766e1a2eb46175aa9 Mon Sep 17 00:00:00 2001 From: tianmo Date: Tue, 15 Sep 2026 11:45:30 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9B=B6=E7=82=B9=E5=8F=82=E8=80=83=E7=BA=BF?= =?UTF-8?q?=E3=80=81=E7=BC=A9=E6=94=BE=E9=80=89=E5=AE=9A=E5=9B=BE=E5=B1=82?= =?UTF-8?q?=E3=80=81=E9=80=8F=E6=98=8E=E5=83=8F=E7=B4=A0=E8=A3=81=E5=88=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jsx/scripts/99.其他工具/零点参考线.jsx | 51 ++++++++++ .../jsx/scripts/缩放选定图层.jsx | 94 +++++++++++++++++++ .../jsx/scripts/透明像素裁切.jsx | 30 ++++++ 3 files changed, 175 insertions(+) create mode 100644 Mac工具/Yeomai-Toolbox-CEP/jsx/scripts/99.其他工具/零点参考线.jsx create mode 100644 Mac工具/Yeomai-Toolbox-CEP/jsx/scripts/缩放选定图层.jsx create mode 100644 Mac工具/Yeomai-Toolbox-CEP/jsx/scripts/透明像素裁切.jsx diff --git a/Mac工具/Yeomai-Toolbox-CEP/jsx/scripts/99.其他工具/零点参考线.jsx b/Mac工具/Yeomai-Toolbox-CEP/jsx/scripts/99.其他工具/零点参考线.jsx new file mode 100644 index 0000000..33a743b --- /dev/null +++ b/Mac工具/Yeomai-Toolbox-CEP/jsx/scripts/99.其他工具/零点参考线.jsx @@ -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); + } +}()); + diff --git a/Mac工具/Yeomai-Toolbox-CEP/jsx/scripts/缩放选定图层.jsx b/Mac工具/Yeomai-Toolbox-CEP/jsx/scripts/缩放选定图层.jsx new file mode 100644 index 0000000..786172b --- /dev/null +++ b/Mac工具/Yeomai-Toolbox-CEP/jsx/scripts/缩放选定图层.jsx @@ -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); + } +}()); diff --git a/Mac工具/Yeomai-Toolbox-CEP/jsx/scripts/透明像素裁切.jsx b/Mac工具/Yeomai-Toolbox-CEP/jsx/scripts/透明像素裁切.jsx new file mode 100644 index 0000000..66ae8f7 --- /dev/null +++ b/Mac工具/Yeomai-Toolbox-CEP/jsx/scripts/透明像素裁切.jsx @@ -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); + } +}()); +