当前位置: 首页 > news >正文

游戏开发中的坑之十四 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 folderprocessFolder(file);} else if (file instanceof File && file.name.match(/\.(tga)$/i)) {// Process TGA filesvar doc = open(file);// Check if the image resolution matches the target resolutionif (doc.width == targetWidth && doc.height == targetHeight) {// Resize the imagedoc.resizeImage(UnitValue(newWidth,"px"), UnitValue(newHeight,"px"), null, ResampleMethod.BICUBIC);// Save the document in TGA formatvar saveOptions = new TargaSaveOptions();saveOptions.resolution = TargaBitsPerPixels.THIRTYTWO; // or choose EIGHT, SIXTEEN, or TWENTYFOURsaveOptions.alphaChannels = true; // Set to false if you don't need alpha channels// Save and close the documentdoc.saveAs(file, saveOptions, true, Extension.LOWERCASE);doc.close(SaveOptions.DONOTSAVECHANGES);} else {// Close the document without savingdoc.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的“首选项”中启用“允许脚本操作”选项。

http://www.lryc.cn/news/375811.html

相关文章:

  • leetcode打卡#day45 携带研究材料(第七期模拟笔试)、518. 零钱兑换 II、377. 组合总和 Ⅳ、爬楼梯(第八期模拟笔试)
  • Vite+Vue3安装且自动按需引入Element Plus组件库
  • 敬酒词大全绝对实用 万能敬酒词
  • 【Java】已解决com.mysql.cj.jdbc.exceptions.CommunicationsException异常
  • Leetcode 76. 最小覆盖子串
  • JAVAWEB--Mybatis03
  • 论文学习_Fuzz4All: Universal Fuzzing with Large Language Models
  • 元数据相关资料整理 metadata
  • 【Android面试八股文】谈一谈你对http和https的关系理解
  • Vue3 中 setup 函数与 script setup 用法总结
  • Springboot 开发之任务调度框架(一)Quartz 简介
  • 企业中面试算法岗时会问什么pytorch问题?看这篇就够了!
  • 【学习】程序员资源网址
  • 【3D模型库】机械三维模型库整理
  • 基于Python-CNN深度学习的物品识别
  • Qt | 简单的使用 QStyle 类(风格也称为样式)
  • Idea连接GitLab的过程以及创建在gitlab中创建用户和群组
  • 关于glibc-all-in-one下载libc2.35以上报错问题
  • C语言之#define #if 预处理器指令
  • modbus流量计数据解析(4个字节与float的换算)
  • 关于element-plus中el-select自定义标签及样式的问题
  • 硕思logo设计师下载-2024官方最新版-logo制作软件安装包下载
  • springboot和mybatis项目学习
  • simdjson 高性能JSON解析C++库
  • 安卓Context上下文
  • 实验13 简单拓扑BGP配置
  • 面试题分享--Spring02
  • 基于QT和C++实现的中国象棋
  • Mojo崛起:AI-first 的编程语言能否成为新流行?
  • 【数据结构与算法】哈夫曼树与哈夫曼编码