️ Copy images instead of regenerating them

This commit is contained in:
trickypr 2022-03-26 21:02:44 +11:00
parent d26f961d0a
commit 0b0cdd1487

View file

@ -7,6 +7,7 @@ import {
writeFileSync, writeFileSync,
copyFileSync, copyFileSync,
} from 'fs' } from 'fs'
import { copyFile } from 'fs/promises'
import { dirname, extname, join } from 'path' import { dirname, extname, join } from 'path'
import sharp from 'sharp' import sharp from 'sharp'
@ -67,13 +68,16 @@ function constructConfig(name: string) {
} }
async function setupImages(configPath: string, outputPath: string) { async function setupImages(configPath: string, outputPath: string) {
// TODO: This can be made parallel to avoid problems with cpu vs disk access
for (const size of [16, 22, 24, 32, 48, 64, 128, 256]) { for (const size of [16, 22, 24, 32, 48, 64, 128, 256]) {
await sharp(join(configPath, 'logo.png')) await sharp(join(configPath, 'logo.png'))
.resize(size, size) .resize(size, size)
.toFile(join(outputPath, `default${size}.png`)) .toFile(join(outputPath, `default${size}.png`))
await sharp(join(configPath, 'logo.png'))
.resize(size, size) await copyFile(
.toFile(join(configPath, `logo${size}.png`)) join(outputPath, `default${size}.png`),
join(configPath, `logo${size}.png`)
)
} }
await sharp(join(configPath, 'logo.png')) await sharp(join(configPath, 'logo.png'))