diff options
author | mat <27899617+mat-1@users.noreply.github.com> | 2022-12-15 20:19:42 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-15 20:19:42 -0600 |
commit | ed5eedab8f9fc90dadf5c442cf559572d1b35f0c (patch) | |
tree | 01a763fd11810e9970f14f7dae180e95b279de9a /scripts/updateBackgrounds.js | |
parent | 89bf3d31e36ad3bdfd45461ee6fb69a4c791f848 (diff) | |
parent | 103689520f51991a1e9a4ca5829fe2f46d1a32c2 (diff) | |
download | skyblock-stats-ed5eedab8f9fc90dadf5c442cf559572d1b35f0c.tar.gz skyblock-stats-ed5eedab8f9fc90dadf5c442cf559572d1b35f0c.tar.bz2 skyblock-stats-ed5eedab8f9fc90dadf5c442cf559572d1b35f0c.zip |
Merge pull request #6 from skyblockstats/sveltekit-v1
Sveltekit v1
Diffstat (limited to 'scripts/updateBackgrounds.js')
-rw-r--r-- | scripts/updateBackgrounds.js | 29 |
1 files changed, 7 insertions, 22 deletions
diff --git a/scripts/updateBackgrounds.js b/scripts/updateBackgrounds.js index 0c3e214..a5467fa 100644 --- a/scripts/updateBackgrounds.js +++ b/scripts/updateBackgrounds.js @@ -1,9 +1,7 @@ import { promises as fs } from 'fs' -import { ImagePool } from '@squoosh/lib' +import sharp from 'sharp' import { cpus } from 'os' -const imagePool = new ImagePool(cpus().length) - // read the file names in the backgrounds folder const backgrounds = await fs.readdir('static/backgrounds') // sort by natural order @@ -18,25 +16,13 @@ await fs.writeFile( // resize the backgrounds async function resizeBackground(name) { - const file = await fs.readFile(`static/backgrounds/${name}`) - const image = imagePool.ingestImage(file) - - const preprocessOptions = { - resize: { - width: 512, - }, - } - await image.preprocess(preprocessOptions) - - await image.encode({ - mozjpeg: { - quality: 30, - }, - }) - - const rawEncodedImage = await image.encodedWith.mozjpeg + const rawEncodedImage = await sharp(`static/backgrounds/${name}`) + .rotate() + .resize(512) + .jpeg({ mozjpeg: true, quality: 30 }) + .toBuffer() - await fs.writeFile(`static/backgrounds-small/${name}`, rawEncodedImage.binary) + await fs.writeFile(`static/backgrounds-small/${name}`, rawEncodedImage) } try { @@ -47,4 +33,3 @@ try { await fs.mkdir('static/backgrounds-small', { recursive: true }) await Promise.all(backgrounds.map(b => resizeBackground(b))) -await imagePool.close() |