script for manually shrinking images

This commit is contained in:
Nycki 2024-11-30 19:35:41 -08:00
parent bc1b77bfae
commit 360dc2b055
5 changed files with 34 additions and 1 deletions

4
.gitignore vendored
View file

@ -3,3 +3,7 @@ node_modules/
package-lock.json
.cache
patches
tools/in/*
!tools/in/.gitkeep
tools/out/*
!tools/out/.gitkeep

View file

@ -8,7 +8,8 @@
"start": "cross-env NODE_ENV=localhost npx @11ty/eleventy --serve --quiet",
"debug": "cross-env DEBUG=Eleventy* npx @11ty/eleventy",
"debugstart": "cross-env DEBUG=Eleventy* npx @11ty/eleventy --serve --quiet",
"benchmark": "cross-env DEBUG=Eleventy:Benchmark* npx @11ty/eleventy"
"benchmark": "cross-env DEBUG=Eleventy:Benchmark* npx @11ty/eleventy",
"img2k": "node tools/img-shrink.js"
},
"repository": {
"type": "git",
@ -39,6 +40,7 @@
"@11ty/eleventy-plugin-rss": "^1.2.0",
"@11ty/eleventy-plugin-syntaxhighlight": "^5.0.0",
"cross-env": "^7.0.3",
"gm": "^1.22.0",
"luxon": "^3.3.0",
"markdown-it-anchor": "^8.6.7"
}

27
tools/img-shrink.js Normal file
View file

@ -0,0 +1,27 @@
// winget install ImageMagick.Q8
const { exec } = require('node:child_process');
const { readdir } = require('node:fs/promises');
const path = require('node:path');
async function main() {
const dirIn = 'tools/in';
const dirOut = 'tools/out';
for (const base of await readdir(dirIn)) {
if (base === '.gitkeep') continue;
const fileIn = `${dirIn}/${base}`;
const file = path.parse(fileIn);
const fileOut = `${dirOut}/${file.name}.webp`;
const lossless = file.ext === '.png';
const cmd = [
`magick "${fileIn}"`,
`-define webp:lossless=${lossless}`,
`-define webp:target-size=200kb`,
`"${fileOut}"`,
].join(' ');
console.log(cmd);
exec(cmd, (_err, stdout, stderr) => console.log(stdout + stderr));
}
}
main();

0
tools/in/.gitkeep Normal file
View file

0
tools/out/.gitkeep Normal file
View file