Download and normalize painting images via sharp

Add sharp dep (libvips bindings) — fastest option for the per-image
center-crop + Lanczos resize step. Pure-JS alternatives (jimp) and
spawning ffmpeg per image were both ~5-10x slower in this hot loop.

Add src/installer-rp/images.ts:
- ytIdFromUrl: extracts the video ID from watch?v=, youtu.be/, and
  /shorts|embed/ URL forms
- downloadImage: for YouTube URLs tries i.ytimg.com/vi/<id>/
  maxresdefault.jpg first, falls back to hqdefault.jpg; plain image
  URLs go through a generic HTTP/HTTPS GET that follows 302s
- normalizeToCover: center-crop to min(w,h), Lanczos resize down to
  1024x1024 when larger, never upscales, writes PNG
- coverFileName: returns cover_NN.png with zero-padded NN

Wire step 2-3 of the install handler to download + normalize each
image into <tempDir>/painting/cover_NN.png. Zip build (step 2-4)
will pick those up next.

Verified with synthetic 1200x800 and 2000x1500 buffers: small
input stays 800x800 (no upscale), large input becomes 1024x1024.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-12 15:30:11 +09:00
parent 5e3a42ff4f
commit 9e96366956
4 changed files with 655 additions and 9 deletions

View File

@@ -12,21 +12,22 @@
"dist:win": "tsc -p tsconfig.installer.json && electron-builder --win"
},
"dependencies": {
"ejs": "^3.1.10",
"express": "^4.19.2",
"express-session": "^1.18.0",
"ejs": "^3.1.10",
"extract-zip": "^2.0.1",
"multer": "^1.4.5-lts.1",
"nat-upnp": "^1.1.1",
"extract-zip": "^2.0.1"
"sharp": "^0.34.5"
},
"devDependencies": {
"typescript": "^5.5.4",
"@types/node": "^22.5.0",
"@types/ejs": "^3.1.5",
"@types/express": "^4.17.21",
"@types/express-session": "^1.18.0",
"@types/ejs": "^3.1.5",
"@types/multer": "^1.4.11",
"@types/node": "^22.5.0",
"electron": "^31.4.0",
"electron-builder": "^24.13.3"
"electron-builder": "^24.13.3",
"typescript": "^5.5.4"
}
}