-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e6757f8
commit 6782808
Showing
3 changed files
with
53 additions
and
26 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ "dependencies": { "sharp": "^0.33.2" }, "devDependencies": { "@types/bun": "latest", "@types/node": "^20.11.19" }, "name": "jg-rtx", "module": "index.ts", "type": "module", "peerDependencies": { | ||
{ "dependencies": { "sharp": "^0.33.3" }, "devDependencies": { "@types/bun": "latest", "@types/node": "^20.11.19" }, "name": "jg-rtx", "module": "index.ts", "type": "module", "peerDependencies": { | ||
"typescript": "^5.0.0" | ||
} } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import sharp from "sharp"; | ||
import { readdir, copyFile, mkdir, stat } from "node:fs/promises"; | ||
import { dirname, basename } from "node:path"; | ||
|
||
const resize = async (input: string, output: string, size?: number) => { | ||
try { | ||
const img = sharp(input); | ||
const { width } = await img.metadata() ?? { width: size ?? 256 }; | ||
|
||
await img.resize(size ?? Math.max(0.5 * width!, 16), null).toFile(output); | ||
} catch (err) { | ||
console.error(`File ${input} could not be resized: ${err}`); | ||
} | ||
}; | ||
|
||
const resizeImages = async (inputDir: string, outputDir: string, width: number) => { | ||
const files = await readdir(inputDir); | ||
for (const file of files) { | ||
const src = `${inputDir}/${file}`; | ||
const dest = `${outputDir}/${file}`; | ||
|
||
if ((await stat(src)).isDirectory()) { | ||
await resizeImages(src, dest, width); | ||
continue; | ||
} | ||
|
||
try { | ||
await mkdir(dirname(dest), { recursive: true }); | ||
} catch (err) { | ||
console.error(`Directory ${dirname(dest)} could not be created: ${err}`); | ||
} | ||
|
||
if (!file.endsWith(".png")) { | ||
// try { | ||
// await copyFile(src, dest); | ||
// console.log(`📋 COPIED ${basename(src)}`); | ||
// } catch (err) { | ||
// console.error(`File ${basename(src)} could not be copied: ${err}`); | ||
// } | ||
continue; | ||
} | ||
|
||
try { | ||
await resize(src, dest, width); | ||
console.log(`📏 RESIZED ${basename(src)}`); | ||
} catch(err) { | ||
console.error(`File ${basename(src)} could not be resized: ${err}`); | ||
} | ||
} | ||
}; | ||
|
||
await resizeImages("../../bedrock/pack/RP/textures/blocks", "../../dist/64x", 64); |