30 lines
919 B
JavaScript
30 lines
919 B
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
// Fallback to Jimp if sharp is not available
|
|
try {
|
|
const Jimp = require('jimp');
|
|
|
|
async function padIconJimp() {
|
|
console.log('Padding icon using Jimp...');
|
|
const img = await Jimp.read('Icon.png');
|
|
// Scale down image to fit within 720x720 while maintaining aspect ratio
|
|
img.scaleToFit(720, 720);
|
|
|
|
// Create a transparent 1080x1080 background
|
|
const bg = new Jimp(1080, 1080, 0x00000000);
|
|
|
|
// Center the scaled image on the background
|
|
const x = (1080 - img.bitmap.width) / 2;
|
|
const y = (1080 - img.bitmap.height) / 2;
|
|
|
|
bg.composite(img, x, y);
|
|
await bg.writeAsync('Icon-padded.png');
|
|
console.log('Icon successfully padded to Icon-padded.png');
|
|
}
|
|
|
|
padIconJimp().catch(console.error);
|
|
} catch (e) {
|
|
console.log('Jimp not found. Please install it first using: npm install jimp --no-save');
|
|
}
|