feat: resize script

This commit is contained in:
trafficlunar 2024-12-21 16:51:12 +00:00
parent bd876eb5c3
commit 606229ed09
3 changed files with 31 additions and 0 deletions

View file

@ -4,6 +4,7 @@
"version": "1.0.0",
"dependencies": {
"fast-average-color-node": "^3.1.0",
"sharp": "^0.33.5",
"spritesheet-js": "^1.2.8"
}
}

View file

@ -11,6 +11,9 @@ importers:
fast-average-color-node:
specifier: ^3.1.0
version: 3.1.0
sharp:
specifier: ^0.33.5
version: 0.33.5
spritesheet-js:
specifier: ^1.2.8
version: 1.2.8

27
generator/resize.js Normal file
View file

@ -0,0 +1,27 @@
const fs = require("fs");
const path = require("path");
const sharp = require("sharp");
const INPUT = path.join(__dirname, "blocks/");
(async () => {
const files = fs.readdirSync(INPUT);
for (const file of files) {
const filePath = path.join(INPUT, file);
const image = sharp(filePath);
const metadata = await image.metadata();
if (metadata.height > 16) {
await image
.extract({ top: 0, left: 0, width: 16, height: 16 })
.resize(16, 16)
.toBuffer()
.then((buffer) => {
fs.writeFileSync(filePath, buffer);
});
}
}
console.log("Done!");
})();