Updated
This commit is contained in:
parent
8e724b166a
commit
b5e92165c8
33 changed files with 82 additions and 223 deletions
23
@dasig/scripts/node/optimizeBackground.ts
Normal file
23
@dasig/scripts/node/optimizeBackground.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import { consola } from "consola";
|
||||
import sharp from "sharp";
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
const inputSrc = 'src/images/background.png'
|
||||
const webpOutput = "./@dasig/images/background.webp"
|
||||
const avifOutput = "./@dasig/images/background.avif"
|
||||
|
||||
const avifBuffer = await sharp(inputSrc).avif({ quality: 60 }).resize(1920).toBuffer()
|
||||
await sharp(avifBuffer).toFile(avifOutput)
|
||||
consola.success('Background successfully optimized in Avif');
|
||||
|
||||
const webpBuffer = await sharp(inputSrc).webp({ quality: 75 }).resize(1920).toBuffer()
|
||||
await sharp(webpBuffer).toFile(webpOutput)
|
||||
consola.success('Background successfully optimized in Webp');
|
||||
|
||||
} catch (error: any) {
|
||||
consola.error("Error optimizing background:", 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