This commit is contained in:
Patrick Alvin Alcala 2025-11-26 10:56:07 +08:00
parent d61b8b7bd8
commit 46783c4f38
57 changed files with 4178 additions and 5992 deletions

View file

@ -0,0 +1,41 @@
import { consola } from 'consola';
import sharp from 'sharp';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
(async () => {
const argv = yargs(hideBin(process.argv))
.option('name', {
alias: 'n',
describe: 'Specify the name of the image',
type: 'string',
demandOption: true,
})
.option('size', {
alias: 's',
describe: 'Specify the size of the image',
type: 'number',
demandOption: true,
})
.argv;
const name = argv.name;
const size = argv.size;
try {
const avifOutputPath = `./src/@dasig/images/${name.toString().split('.').slice(0, -1).join('.')}.avif`
const webpOutputPath = `./src/@dasig/images/${name.toString().split('.').slice(0, -1).join('.')}.webp`
const avifBuffer = await sharp(`./src/images/${name}`).avif({ quality: 60 }).resize(size).toBuffer()
await sharp(avifBuffer).toFile(avifOutputPath)
consola.success(`${name} successfully optimized in Avif`)
const webpBuffer = await sharp(`./src/images/${name}`).webp({ quality: 75 }).resize(size).toBuffer()
await sharp(webpBuffer).toFile(webpOutputPath)
consola.success(`${name} successfully optimized in Webp`)
} catch (error) {
consola.error('Error optimizing image:', error)
if (error.message.includes('missing')) consola.error(`${name} could not be found on image folder`)
}
})()