游戏开发中的坑之十四 photoshop的javascript脚本批量修改分辨率

原因:美术提交大量2048x2048的贴图,导致工程臃肿。

方案:使用photoshop的javascript脚本批量把指定的文件夹以及所有子文件夹的贴图进行压缩。

           脚本中指定针对2048x2048的贴图进行处理。

// Photoshop JavaScript to resize TGA images with specific resolution
// and process all subfolders

// Change the folder path to the folder containing your TGA images
var inputFolder = Folder.selectDialog("Select the root folder containing TGA images");

// The target resolution
var targetWidth = 2048;
var targetHeight = 2048;

// The new size (change these values to what you need)
var newWidth = 1024;
var newHeight = 1024;

// Function to recursively process a folder
function processFolder(folder) {
    var files = folder.getFiles();
    
    for (var i = 0; i < files.length; i++) {
        var file = files[i];
        
        if (file instanceof Folder) {
            // Call the function recursively if it's a folder
            processFolder(file);
        } else if (file instanceof File && file.name.match(/\.(tga)$/i)) {
            // Process TGA files
            var doc = open(file);
            
            // Check if the image resolution matches the target resolution
            if (doc.width == targetWidth && doc.height == targetHeight) {
                // Resize the image
                doc.resizeImage(UnitValue(newWidth,"px"), UnitValue(newHeight,"px"), null, ResampleMethod.BICUBIC);
                
                // Save the document in TGA format
                var saveOptions = new TargaSaveOptions();
                saveOptions.resolution = TargaBitsPerPixels.THIRTYTWO; // or choose EIGHT, SIXTEEN, or TWENTYFOUR
                saveOptions.alphaChannels = true; // Set to false if you don't need alpha channels
                
                // Save and close the document
                doc.saveAs(file, saveOptions, true, Extension.LOWERCASE);
                doc.close(SaveOptions.DONOTSAVECHANGES);
            } else {
                // Close the document without saving
                doc.close(SaveOptions.DONOTSAVECHANGES);
            }
        }
    }
}

// Run the function if a folder was selected
if (inputFolder) {
    processFolder(inputFolder);
    alert("Processing complete!");
}

请按照以下步骤使用此脚本:

  1. 打开文本编辑器,如Notepad或TextEdit。
  2. 将上述代码复制并粘贴到文本编辑器中。
  3. 根据您的需求,修改newWidth和newHeight变量来设置新的尺寸。
  4. 将文件保存为扩展名为.jsx的文件,例如resizeTGA.jsx。
  5. 打开Photoshop。
  6. 选择“文件” > “脚本” > “浏览”并选择您保存的.jsx文件来运行脚本。

确保在运行脚本之前备份您的图片。此外,根据您的Photoshop版本和设置,您可能需要在Photoshop的“首选项”中启用“允许脚本操作”选项。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值