chore: upload parte 2 - assets
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import sharp from 'sharp';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
const logoUrl = 'https://hebbkx1anhila5yf.public.blob.vercel-storage.com/Preto_semfundo-QjUexykfB10GjO803zcUlswqR19RBV.png';
|
||||
|
||||
const res = await fetch(logoUrl);
|
||||
const arrayBuffer = await res.arrayBuffer();
|
||||
const inputBuffer = Buffer.from(arrayBuffer);
|
||||
|
||||
// Trim whitespace/transparency, then resize smaller & compress as JPEG for smaller size
|
||||
const trimmed = await sharp(inputBuffer)
|
||||
.trim() // remove transparent/white borders
|
||||
.resize({ width: 400, fit: 'inside' }) // resize to max 400px wide
|
||||
.png({ quality: 60, compressionLevel: 9 })
|
||||
.toBuffer();
|
||||
|
||||
const base64 = trimmed.toString('base64');
|
||||
const dataUrl = `data:image/png;base64,${base64}`;
|
||||
|
||||
console.log(`Original size: ${inputBuffer.length} bytes`);
|
||||
console.log(`Cropped+compressed size: ${trimmed.length} bytes`);
|
||||
console.log(`Base64 length: ${base64.length} chars`);
|
||||
|
||||
// Output full data URL so we can embed it
|
||||
console.log('DATA_URL_START');
|
||||
console.log(dataUrl);
|
||||
console.log('DATA_URL_END');
|
||||
Reference in New Issue
Block a user