29 lines
1.6 KiB
JavaScript
29 lines
1.6 KiB
JavaScript
// Technical build-time resampling/compression only; artwork and alpha are preserved.
|
|||
|
|
// Requires sharp (available in the bundled workspace runtime), no network requests.
|
||
|
|
const path = require('node:path')
|
||
|
|
const fs = require('node:fs')
|
||
|
|
const sharp = require('sharp')
|
||
|
|
const source = process.argv[2]
|
||
|
|
if (!source) throw new Error('Pass the directory exported by the browser pageAssets capability')
|
||
|
|
const output = path.resolve(__dirname, '../src/assets/tiangong')
|
||
|
|
const jobs = [
|
||
|
|
['5ee867165b3314a2.png', 'wealth', 'icon'],
|
||
|
|
['d00ddb9d78132e08.png', 'fortune', 'icon'],
|
||
|
|
['c8acca9ecd8bf75b.png', 'longevity', 'icon'],
|
||
|
|
['6b935cc3a3f6178e.png', 'wenchang', 'icon'],
|
||
|
|
['778c1072c4dcdcbe.png', 'matchmaker', 'icon'],
|
||
|
|
['295b80249bc5355a.png', 'wealth-statue', 'statue'],
|
||
|
|
['1d88a8dcad0553ef.png', 'fortune-statue', 'statue'],
|
||
|
|
['c7ef27f2d9dcc38a.png', 'clouds', 'background'],
|
||
|
|
['f0bcdd293f5f5ef3.jpg', 'altar', 'altar'],
|
||
|
|
['01b38f88c3e69699.jpg', 'altar-lit', 'altar']
|
||
|
|
]
|
||
|
|
;(async () => {
|
||
|
|
for (const [filename, name, kind] of jobs) {
|
||
|
|
const asset = sharp(path.join(source, filename))
|
||
|
|
const destination = path.join(output, `proto-${name}.${kind === 'statue' ? 'png' : 'jpg'}`)
|
||
|
|
if (kind === 'statue') await asset.resize(640, 640, { fit: 'inside' }).png({ palette: true, colours: 128, quality: 80, effort: 10, compressionLevel: 9 }).toFile(destination)
|
||
|
|
else await asset.resize({ width: kind === 'icon' ? 384 : kind === 'altar' ? 800 : 540, withoutEnlargement: true }).jpeg({ quality: 76, mozjpeg: true }).toFile(destination)
|
||
|
|
console.log(path.basename(destination), fs.statSync(destination).size)
|
||
|
|
}
|
||
|
|
})().catch(error => { console.error(error); process.exitCode = 1 })
|