Created optimizedLogo
This commit is contained in:
parent
c8eab94bf9
commit
217b7fa3d7
1 changed files with 30 additions and 0 deletions
30
src/utils/scripts/optimizeLogo.js
Normal file
30
src/utils/scripts/optimizeLogo.js
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
import sharp from 'sharp'
|
||||||
|
import * as fs from 'fs'
|
||||||
|
import * as path from 'path'
|
||||||
|
import { consola } from 'consola'
|
||||||
|
;(async () => {
|
||||||
|
try {
|
||||||
|
const dirPath = path.resolve('../../../public')
|
||||||
|
const webpImage = 'src/assets/images/optimized/logo.webp'
|
||||||
|
const avifImage = 'src/assets/images/optimized/logo.avif'
|
||||||
|
const inputSrc = 'src/assets/images/logo.png'
|
||||||
|
|
||||||
|
const avifBuffer = await sharp(inputSrc).avif({ quality: 60 }).resize(props.size).toBuffer()
|
||||||
|
await sharp(avifBuffer).toFile(avifImage)
|
||||||
|
|
||||||
|
const webpBuffer = await sharp(inputSrc).webp({ quality: 75 }).resize(props.size).toBuffer()
|
||||||
|
await sharp(webpBuffer).toFile(webpImage)
|
||||||
|
|
||||||
|
if (fs.existsSync(dirPath)) {
|
||||||
|
const inputSrc = '../../assets/images/logo.png'
|
||||||
|
const favicon = dirPath + '/favicon.png'
|
||||||
|
const faviconBuffer = await sharp(inputSrc).png({ quality: 90 }).resize(50).toBuffer()
|
||||||
|
await sharp(faviconBuffer).toFile(favicon)
|
||||||
|
consola.success('Favicon generated successfully')
|
||||||
|
} else {
|
||||||
|
consola.error('Directory does not exist:', dirPath)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
consola.error('Error generating favicon:', error)
|
||||||
|
}
|
||||||
|
})()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue