Updated
This commit is contained in:
parent
d61b8b7bd8
commit
46783c4f38
57 changed files with 4178 additions and 5992 deletions
41
frontend/@dasig/scripts/node/optimizeImage.js
Normal file
41
frontend/@dasig/scripts/node/optimizeImage.js
Normal 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`)
|
||||
}
|
||||
})()
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue