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
This commit is contained in:
@@ -698,6 +698,42 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
||||
}
|
||||
});
|
||||
|
||||
// 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 {
|
||||
|
||||
Reference in New Issue
Block a user