nodejs 拆分 egret 合图

2022-05-09  本文已影响0人  欧特雨
const images = require("images");
const fs = require('fs');
const path = require('path');

let url = 'url'
let url_png = url + '.png';
let url_json = url + '.json';

// 创建
const absPath = path.resolve(__dirname, url);
if (!fs.existsSync(absPath)) {
    fs.mkdirSync(absPath);
}

let json_data = fs.readFileSync(url_json);
let json = JSON.parse(json_data)

let big_image = images(url_png);

for (let id in json.frames) {
    let png_data = json.frames[id];
    let single_png = images(big_image, png_data.x, png_data.y, png_data.w, png_data.h);
    images(png_data.sourceW, png_data.sourceH)
        .draw(single_png, png_data.offX, png_data.offY)
        .save(url + '/' + id + ".png", {
            quality: 100
        });
}

上一篇下一篇

猜你喜欢

热点阅读