chore: replace paths
@@ -40,12 +40,12 @@ export default defineConfig({
|
|||||||
name: site.title,
|
name: site.title,
|
||||||
icons: [
|
icons: [
|
||||||
{
|
{
|
||||||
src: '/assets/images/branding/favicons/favicon-192.png',
|
src: '/assets/images/favicons/favicon-192.png',
|
||||||
sizes: '192x192',
|
sizes: '192x192',
|
||||||
type: 'image/png',
|
type: 'image/png',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
src: '/assets/images/branding/favicons/favicon-512.png',
|
src: '/assets/images/favicons/favicon-512.png',
|
||||||
sizes: '512x512',
|
sizes: '512x512',
|
||||||
type: 'image/png',
|
type: 'image/png',
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,60 +1,32 @@
|
|||||||
const Jimp = require('jimp');
|
const sharp = require('sharp');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
// Define the path to the input and output folders
|
const inputFolder = './src/images/cover/';
|
||||||
const inputFolder = './public/assets/images/cover/';
|
const outputFolder = './public/assets/images/og/';
|
||||||
const outputFolder = './public/assets/images/branding/og/';
|
|
||||||
|
|
||||||
// Define the aspect ratio to crop the final image to
|
|
||||||
const cropSize = { ratio: 16 / 9 };
|
|
||||||
|
|
||||||
// Define the size to resize the final image to
|
|
||||||
const resizeSize = { width: 1200, height: 675 };
|
const resizeSize = { width: 1200, height: 675 };
|
||||||
|
|
||||||
// Loop through each image in the input folder
|
|
||||||
fs.readdir(inputFolder, async (err, files) => {
|
fs.readdir(inputFolder, async (err, files) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
if (
|
if (/\.(webp|png|jpg|jpeg)$/i.test(file)) {
|
||||||
file.toLowerCase().endsWith('.png') ||
|
|
||||||
file.toLowerCase().endsWith('.jpg') ||
|
|
||||||
file.toLowerCase().endsWith('.jpeg')
|
|
||||||
) {
|
|
||||||
// Open the input image
|
|
||||||
const inputImagePath = path.join(inputFolder, file);
|
const inputImagePath = path.join(inputFolder, file);
|
||||||
const inputImage = await Jimp.read(inputImagePath);
|
const outputFilename = path.parse(file).name + '.jpg';
|
||||||
|
const outputImagePath = path.join(outputFolder, outputFilename);
|
||||||
|
|
||||||
// Resize and crop the input image to fit within the desired size and aspect ratio
|
const textImagePath = './public/assets/images/template/text.png';
|
||||||
inputImage.cover(resizeSize.width, resizeSize.height);
|
|
||||||
|
|
||||||
// Open the text image
|
await sharp(inputImagePath)
|
||||||
const textImagePath = './public/assets/images/branding/template/text.png';
|
.resize({
|
||||||
const textImage = await Jimp.read(textImagePath);
|
width: resizeSize.width,
|
||||||
|
height: resizeSize.height,
|
||||||
|
fit: 'cover',
|
||||||
|
})
|
||||||
|
.composite([{ input: textImagePath, gravity: 'center' }])
|
||||||
|
.jpeg({ quality: 70 })
|
||||||
|
.toFile(outputImagePath);
|
||||||
|
|
||||||
// Create a new image with the same size as the input image
|
console.log(`Generated: ${outputFilename}`);
|
||||||
const combinedImage = new Jimp(
|
|
||||||
inputImage.bitmap.width,
|
|
||||||
inputImage.bitmap.height,
|
|
||||||
0x00000000
|
|
||||||
);
|
|
||||||
|
|
||||||
// Reduce the quality of the combined image to 70%
|
|
||||||
combinedImage.quality(70);
|
|
||||||
|
|
||||||
// Paste the input image onto the new image
|
|
||||||
combinedImage.composite(inputImage, 0, 0);
|
|
||||||
|
|
||||||
// Calculate the position to center the text image
|
|
||||||
const x = (inputImage.bitmap.width - textImage.bitmap.width) / 2;
|
|
||||||
const y = (inputImage.bitmap.height - textImage.bitmap.height) / 2;
|
|
||||||
|
|
||||||
// Paste the text image onto the new image
|
|
||||||
combinedImage.composite(textImage, x, y);
|
|
||||||
|
|
||||||
// Save the final image to the output folder with the same filename as the input image
|
|
||||||
const outputImagePath = path.join(outputFolder, file);
|
|
||||||
await combinedImage.writeAsync(outputImagePath);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 88 KiB |
|
Before Width: | Height: | Size: 111 KiB |
|
Before Width: | Height: | Size: 76 KiB |
|
Before Width: | Height: | Size: 95 KiB |
|
Before Width: | Height: | Size: 73 KiB |
|
Before Width: | Height: | Size: 72 KiB |
|
Before Width: | Height: | Size: 83 KiB |
|
Before Width: | Height: | Size: 146 KiB |
|
Before Width: | Height: | Size: 90 KiB |
|
Before Width: | Height: | Size: 83 KiB |
|
Before Width: | Height: | Size: 87 KiB |
|
Before Width: | Height: | Size: 109 KiB |
|
Before Width: | Height: | Size: 110 KiB |
|
Before Width: | Height: | Size: 89 KiB |
|
Before Width: | Height: | Size: 69 KiB |
|
Before Width: | Height: | Size: 131 KiB |
|
Before Width: | Height: | Size: 144 KiB |
|
Before Width: | Height: | Size: 113 KiB |
|
Before Width: | Height: | Size: 120 KiB |
|
Before Width: | Height: | Size: 148 KiB |
|
Before Width: | Height: | Size: 140 KiB |
|
Before Width: | Height: | Size: 113 KiB |
|
Before Width: | Height: | Size: 98 KiB |
|
Before Width: | Height: | Size: 121 KiB |
|
Before Width: | Height: | Size: 117 KiB |
|
Before Width: | Height: | Size: 105 KiB |
|
Before Width: | Height: | Size: 93 KiB |
|
Before Width: | Height: | Size: 165 KiB |
|
Before Width: | Height: | Size: 49 KiB |
|
Before Width: | Height: | Size: 65 KiB |
|
Before Width: | Height: | Size: 115 KiB |
|
Before Width: | Height: | Size: 96 KiB |
|
Before Width: | Height: | Size: 132 KiB |
|
Before Width: | Height: | Size: 90 KiB |
|
Before Width: | Height: | Size: 88 KiB |
|
Before Width: | Height: | Size: 52 KiB |
|
Before Width: | Height: | Size: 80 KiB |
|
Before Width: | Height: | Size: 67 KiB |
|
Before Width: | Height: | Size: 61 KiB |
|
Before Width: | Height: | Size: 87 KiB |
|
Before Width: | Height: | Size: 79 KiB |
|
Before Width: | Height: | Size: 110 KiB |
|
Before Width: | Height: | Size: 119 KiB |
|
Before Width: | Height: | Size: 91 KiB |
|
Before Width: | Height: | Size: 99 KiB |
|
Before Width: | Height: | Size: 103 KiB |
|
Before Width: | Height: | Size: 105 KiB |
|
Before Width: | Height: | Size: 68 KiB |
|
Before Width: | Height: | Size: 90 KiB |
|
Before Width: | Height: | Size: 80 KiB |
|
Before Width: | Height: | Size: 68 KiB |
|
Before Width: | Height: | Size: 68 KiB |
|
Before Width: | Height: | Size: 82 KiB |
|
Before Width: | Height: | Size: 68 KiB |
|
Before Width: | Height: | Size: 119 KiB |
|
Before Width: | Height: | Size: 70 KiB |
|
Before Width: | Height: | Size: 58 KiB |
|
Before Width: | Height: | Size: 87 KiB |
|
Before Width: | Height: | Size: 89 KiB |
|
Before Width: | Height: | Size: 96 KiB |
|
Before Width: | Height: | Size: 100 KiB |
|
Before Width: | Height: | Size: 91 KiB |
|
Before Width: | Height: | Size: 91 KiB |
|
Before Width: | Height: | Size: 72 KiB |
|
Before Width: | Height: | Size: 81 KiB |
|
Before Width: | Height: | Size: 97 KiB |
|
Before Width: | Height: | Size: 59 KiB |
|
Before Width: | Height: | Size: 120 KiB |
|
Before Width: | Height: | Size: 148 KiB |
|
Before Width: | Height: | Size: 133 KiB |
|
Before Width: | Height: | Size: 66 KiB |
|
Before Width: | Height: | Size: 89 KiB |
|
Before Width: | Height: | Size: 76 KiB |
|
Before Width: | Height: | Size: 78 KiB |
|
Before Width: | Height: | Size: 114 KiB |
|
Before Width: | Height: | Size: 103 KiB |
|
Before Width: | Height: | Size: 104 KiB |
|
Before Width: | Height: | Size: 106 KiB |
|
Before Width: | Height: | Size: 139 KiB |
|
Before Width: | Height: | Size: 107 KiB |
|
Before Width: | Height: | Size: 96 KiB |
|
Before Width: | Height: | Size: 68 KiB |
|
Before Width: | Height: | Size: 73 KiB |
|
Before Width: | Height: | Size: 54 KiB |
|
Before Width: | Height: | Size: 68 KiB |
|
Before Width: | Height: | Size: 83 KiB |
|
Before Width: | Height: | Size: 40 KiB |
|
Before Width: | Height: | Size: 56 KiB |
|
Before Width: | Height: | Size: 70 KiB |
|
Before Width: | Height: | Size: 116 KiB |
|
Before Width: | Height: | Size: 152 KiB |
|
Before Width: | Height: | Size: 52 KiB |
|
Before Width: | Height: | Size: 112 KiB |
|
Before Width: | Height: | Size: 77 KiB |
|
Before Width: | Height: | Size: 75 KiB |
|
Before Width: | Height: | Size: 58 KiB |
|
Before Width: | Height: | Size: 85 KiB |
|
Before Width: | Height: | Size: 63 KiB |