Updated
This commit is contained in:
parent
baed4fd80e
commit
fec3abd5d8
15 changed files with 141 additions and 119 deletions
Binary file not shown.
|
Before Width: | Height: | Size: 846 B |
Binary file not shown.
|
Before Width: | Height: | Size: 626 B |
Binary file not shown.
|
Before Width: | Height: | Size: 1.4 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.6 KiB |
|
|
@ -1,23 +0,0 @@
|
|||
import { consola } from 'consola';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import sharp from 'sharp';
|
||||
|
||||
try {
|
||||
const dirPath = path.resolve('./public')
|
||||
|
||||
if (fs.existsSync(dirPath)) {
|
||||
const inputSrc = './src/images/favicon.png'
|
||||
const favicon = dirPath + '/favicon.png'
|
||||
const faviconBuffer = await sharp(inputSrc).png({ quality: 90 }).resize(48).toBuffer()
|
||||
await sharp(faviconBuffer).toFile(favicon)
|
||||
consola.success('Favicon generated successfully')
|
||||
} else {
|
||||
consola.error('Directory does not exist:', dirPath)
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
if (error.message.includes('missing')) {
|
||||
consola.error('Source favicon does not exist')
|
||||
}
|
||||
}
|
||||
26
frontend/@dasig/scripts/node/generateFavicon.ts
Normal file
26
frontend/@dasig/scripts/node/generateFavicon.ts
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
// deno-lint-ignore-file no-explicit-any
|
||||
import { consola } from "consola";
|
||||
import * as fs from "node:fs";
|
||||
import * as path from "node:path";
|
||||
import sharp from "sharp";
|
||||
|
||||
try {
|
||||
const dirPath = path.resolve("./public");
|
||||
|
||||
if (fs.existsSync(dirPath)) {
|
||||
const inputSrc = "./src/images/favicon.png";
|
||||
const favicon = dirPath + "/favicon.png";
|
||||
const faviconBuffer = await sharp(inputSrc)
|
||||
.png({ quality: 90 })
|
||||
.resize(48)
|
||||
.toBuffer();
|
||||
await sharp(faviconBuffer).toFile(favicon);
|
||||
consola.success("Favicon generated successfully");
|
||||
} else {
|
||||
consola.error("Directory does not exist:", dirPath);
|
||||
}
|
||||
} catch (error: any) {
|
||||
if (error.message.includes("missing")) {
|
||||
consola.error("Source favicon does not exist");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
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`)
|
||||
}
|
||||
})()
|
||||
|
||||
49
frontend/@dasig/scripts/node/optimizeImage.ts
Normal file
49
frontend/@dasig/scripts/node/optimizeImage.ts
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
// deno-lint-ignore-file no-explicit-any
|
||||
|
||||
import { consola } from "consola";
|
||||
import process from "node:process";
|
||||
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 = `./@dasig/images/${name.toString().split(".").slice(0, -1).join(".")}.avif`;
|
||||
const webpOutputPath = `./@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: any) {
|
||||
consola.error("Error optimizing image:", error);
|
||||
if (error.message.includes("missing"))
|
||||
consola.error(`${name} could not be found on image folder`);
|
||||
}
|
||||
})();
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
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('size', {
|
||||
alias: 's',
|
||||
describe: 'Specify the size of the logo',
|
||||
type: 'number',
|
||||
demandOption: true,
|
||||
})
|
||||
.argv;
|
||||
|
||||
const size = argv.size;
|
||||
|
||||
try {
|
||||
const webpImage = './src/@dasig/images/logo.webp'
|
||||
const avifImage = './src/@dasig/images/logo.avif'
|
||||
const inputSrc = './src/images/logo.png'
|
||||
|
||||
const avifBuffer = await sharp(inputSrc).avif({ quality: 60 }).resize(size).toBuffer()
|
||||
await sharp(avifBuffer).toFile(avifImage)
|
||||
consola.success('Logo successfully optimized in Avif')
|
||||
|
||||
const webpBuffer = await sharp(inputSrc).webp({ quality: 75 }).resize(size).toBuffer()
|
||||
await sharp(webpBuffer).toFile(webpImage)
|
||||
consola.success('Logo successfully optimized in Webp')
|
||||
} catch (error) {
|
||||
consola.error('Error generating favicon:', error)
|
||||
}
|
||||
})()
|
||||
36
frontend/@dasig/scripts/node/optimizeLogo.ts
Normal file
36
frontend/@dasig/scripts/node/optimizeLogo.ts
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import { consola } from "consola";
|
||||
import process from "node:process";
|
||||
import sharp from "sharp";
|
||||
import yargs from "yargs";
|
||||
import { hideBin } from "yargs/helpers";
|
||||
|
||||
(async () => {
|
||||
const size = yargs(hideBin(process.argv)).option("size", {
|
||||
alias: "s",
|
||||
describe: "Specify the size of the logo",
|
||||
type: "number",
|
||||
demandOption: true,
|
||||
}).argv.size;
|
||||
|
||||
try {
|
||||
const webpImage = "./@dasig/images/logo.webp";
|
||||
const avifImage = "./@dasig/images/logo.avif";
|
||||
const inputSrc = "./src/images/logo.png";
|
||||
|
||||
const avifBuffer = await sharp(inputSrc)
|
||||
.avif({ quality: 60 })
|
||||
.resize(size)
|
||||
.toBuffer();
|
||||
await sharp(avifBuffer).toFile(avifImage);
|
||||
consola.success("Logo successfully optimized in Avif");
|
||||
|
||||
const webpBuffer = await sharp(inputSrc)
|
||||
.webp({ quality: 75 })
|
||||
.resize(size)
|
||||
.toBuffer();
|
||||
await sharp(webpBuffer).toFile(webpImage);
|
||||
consola.success("Logo successfully optimized in Webp");
|
||||
} catch (error) {
|
||||
consola.error("Error generating favicon:", error);
|
||||
}
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue