(srcPath, outPath)
| 79 | } |
| 80 | |
| 81 | async function processOne(srcPath, outPath) { |
| 82 | const { data, info } = await sharp(srcPath) |
| 83 | .ensureAlpha() |
| 84 | .raw() |
| 85 | .toBuffer({ resolveWithObject: true }); |
| 86 | |
| 87 | const rgba = Buffer.from(data); |
| 88 | removeOuterBackground(rgba, info.width, info.height); |
| 89 | const bounds = getBounds(rgba, info.width, info.height); |
| 90 | |
| 91 | await sharp(rgba, { |
| 92 | raw: { width: info.width, height: info.height, channels: 4 }, |
| 93 | }) |
| 94 | .extract(bounds) |
| 95 | .png({ compressionLevel: 9, adaptiveFiltering: true }) |
| 96 | .toFile(outPath); |
| 97 | |
| 98 | const meta = await sharp(outPath).metadata(); |
| 99 | console.log( |
| 100 | `${path.basename(outPath)} -> ${meta.width}x${meta.height}, ${fs.statSync(outPath).size} bytes` |
| 101 | ); |
| 102 | } |
| 103 | |
| 104 | fs.mkdirSync(outDir, { recursive: true }); |
| 105 |
no test coverage detected