From 1d1cbe4271bb41a3a1b8672a215499e707c30b94 Mon Sep 17 00:00:00 2001 From: sebastjanartic <45803536-sebastjanartic@users.noreply.replit.com> Date: Tue, 2 Sep 2025 18:44:01 +0000 Subject: [PATCH] Improve social media sharing image generation for better platform visibility Add an API endpoint to generate optimized social share images, resolving issues with image display on platforms like WhatsApp. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 2cd2c0bc-434c-4bc9-ad3f-b99d3897a0d1 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/8cc42625-c1f5-4e43-99bd-77f2c4dedee2/2cd2c0bc-434c-4bc9-ad3f-b99d3897a0d1/OdlP8Wj --- client/index.html | 7 ++++--- server/routes.ts | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/client/index.html b/client/index.html index 8a9f69b..5a5b642 100644 --- a/client/index.html +++ b/client/index.html @@ -11,8 +11,9 @@ - - + + + @@ -22,7 +23,7 @@ - + diff --git a/server/routes.ts b/server/routes.ts index fc17268..2d1b091 100644 --- a/server/routes.ts +++ b/server/routes.ts @@ -698,6 +698,42 @@ export async function registerRoutes(app: Express): Promise { } }); + // Optimized social image endpoint + app.get('/api/social-image', async (req, res) => { + try { + const fs = await import('fs'); + const path = await import('path'); + + // Read the original social share image + const imagePath = path.join(process.cwd(), 'client/public/go4-video-social-share.png'); + + if (!fs.existsSync(imagePath)) { + return res.status(404).send('Social image not found'); + } + + const originalImage = fs.readFileSync(imagePath); + + // Optimize with Sharp for WhatsApp/social media (under 300KB) + const optimizedBuffer = await sharp(originalImage) + .resize(1200, 630, { fit: 'cover' }) + .png({ + quality: 80, + compressionLevel: 9, + progressive: true + }) + .toBuffer(); + + res.setHeader('Content-Type', 'image/png'); + res.setHeader('Cache-Control', 'public, max-age=86400'); // Cache for 24 hours + res.setHeader('Content-Length', optimizedBuffer.length); + res.send(optimizedBuffer); + + } catch (error) { + console.error('Error generating optimized social image:', error); + res.status(500).send('Error generating social image'); + } + }); + // Favicon generation endpoint app.get('/api/favicon', async (req, res) => { try {