#target photoshop
try {
var inputFolder = Folder.selectDialog("请选择包含PNG图片的文件夹");
if (!inputFolder) throw "未选择文件夹";
var outputFolder = new Folder(inputFolder.fsName + "/processed");
if (!outputFolder.exists) outputFolder.create();
var files = inputFolder.getFiles("*.png");
if (files.length === 0) throw "未找到PNG文件";
var originalRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;
var successCount = 0;
var skipCount = 0;
for (var i = 0; i < files.length; i++) {
var file = files[i];
if (file instanceof File) {
var result = processImage(file, outputFolder);
if (result === "success") successCount++;
else skipCount++;
}
}
preferences.rulerUnits = originalRulerUnits;
alert("处理完成!\n" +
"成功处理: " + successCount + " 个文件\n" +
"跳过文件: " + skipCount + " (非1:1比例)\n" +
"输出位置: " + outputFolder.fsName);
} catch (e) {
alert("错误: " + e);
}
function processImage(file, outputFolder) {
var doc;
try {
doc = open(file);
if (Math.abs(doc.width.value - doc.height.value) > 0.1) {
throw file.name + " 不是1:1比例图片";
}
doc.resizeImage(192, 192, null, ResampleMethod.BICUBICSHARPER);
try {
var vibranceLayer = doc.artLayers.add();
vibranceLayer.kind = LayerKind.ADJUSTMENT;
vibranceLayer.name = "Vibrance Adjustment";
var vibrance = new Vibrance();
vibrance.vibrance = 50;
vibranceLayer.adjustVibrance = vibrance;
} catch (e) {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putClass( stringIDToTypeID( "vibrance" ) );
desc.putReference( stringIDToTypeID( "null" ), ref );
var vibranceDesc = new ActionDescriptor();
vibranceDesc.putInteger( stringIDToTypeID( "vibrance" ), 50 );
vibranceDesc.putInteger( stringIDToTypeID( "saturation" ), 0 );
desc.putObject( stringIDToTypeID( "using" ), stringIDToTypeID( "vibrance" ), vibranceDesc );
executeAction( stringIDToTypeID( "make" ), desc, DialogModes.NO );
}
doc.flatten();
var pngOptions = new PNGSaveOptions();
pngOptions.compression = 6;
pngOptions.interlaced = false;
var outputName = file.name.replace(/\.[^\.]+$/, "_processed.png");
var outputFile = new File(outputFolder.fsName + "/" + outputName);
doc.saveAs(outputFile, pngOptions, true);
return "success";
} catch (e) {
alert("处理失败: " + file.name + "\n原因: " + e);
return "skip";
} finally {
if (doc) doc.close(SaveOptions.DONOTSAVECHANGES);
}
}
console