pre-commit-image-resize
v0.0.1
Published
Pre-commit hook that auto-resizes oversized images in src/content/posts/
Readme
pre-commit-image-resize
Pre-commit hook that automatically resizes oversized images before they enter the repo. Drop any resolution image into a post folder, commit, and it gets right-sized silently.
- Watches
src/content/posts/**for staged images - Resizes anything wider than 1200px, preserving aspect ratio
- Re-stages the resized file so the commit includes the corrected version
- Logs before/after dimensions for each resized file
- Never blocks a commit — auto-fixes only
- Works in projects with
"type": "module"(ESM-safe hook installation)
Setup
Install as a dev dependency:
npm install -D pre-commit-image-resizeInstall the git hook:
npx pre-commit-image-resize setupThat's it. The hook runs automatically on every git commit.
What it looks like
$ git commit -m "add kyoto post"
resized: src/content/posts/kyoto-day-1/hero.png: 3840×2160 → 1200×675
[main a1b2c3d] add kyoto postImages already within 1200px wide are left untouched with no output.
Bypass
git commit --no-verifyIf a hook already exists
Setup aborts with a message. Remove the existing hook manually, or use --force to overwrite (backs up the original to pre-commit.bak):
npx pre-commit-image-resize setup --forceSupported formats
.jpg, .jpeg, .png, .webp
