跳至内容

Jixun's Blog 填坑还是开坑,这是个好问题。

NTR CFW 截图批量合并脚本

用途 #

NTR CFW 的截图会生成两个文件:top_xxxx.bmpbot_xxxx.bmp

然而,大多数情况下.. 你需要合并 NTR CFW 截图产生的上下屏文件到一个文件。

因此,我决定写一个这样的脚本帮助我一次性处理所有图片。

需求 #

  • 安装 NodeJS 并确保支援 es6 语法
  • 安装 ImageMagick,并可以直接从终端/命令行访问。

代码 #

/**
 * ntr screenshot merger.
 * Windows:   Ensure directory of `convert.exe` is prepend to %PATH% before execute.
 * Linux/Mac: Install ImageMagick Package.
 * 
 * @author Jixun<https://jixun.uk/>
 * @license MIT License<https://opensource.org/licenses/MIT>
 */

const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');

let dir = process.argv[2] || process.cwd();
let outDir = process.argv[3] || path.join(dir, 'out');
let names = fs.readdirSync(dir);

if (!fs.existsSync(outDir)) {
  fs.mkdirSync(outDir);
}

names.forEach(name => {
  let m = name.match(/^top_(\d{4})\.bmp$/i);
  if (m) {
    let in_top = path.join(dir, name);
    let in_bot = path.join(dir, `bot_${m[1]}.bmp`);
    let output = path.join(outDir, `${m[1]}.png`);
    
    console.info(`Merging image ${m[1]} ...`);
    execSync(`convert "${in_top}" -background black "${in_bot}" -gravity center -append "${output}"`);
  }
});

使用 #

$ node ntr_merge.js [[source dir] output dir]

Params:
source dir: Default to "current directory"
output dir: Default to "source dir/out"

授权协议 #

MIT 授权协议,可二次分发,保留作者标示即可。

知识共享许可协议 本作品采用知识共享署名-相同方式共享 4.0 国际许可协议进行许可。

评论区