游戏开发中的坑之十四

发布于:2024-06-17 ⋅ 阅读:(88) ⋅ 点赞:(0)

原因:美术提交大量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的“首选项”中启用“允许脚本操作”选项。


网站公告

今日签到

点亮在社区的每一天
去签到