UNPKG

pixel-forge

Version:

A comprehensive generator for social media previews, favicons, and visual assets across all platforms

151 lines (150 loc) 6.33 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.WhatsAppGenerator = void 0; const path_1 = __importDefault(require("path")); const image_processor_1 = require("../../core/image-processor"); class WhatsAppGenerator { constructor(sourceImage, config) { this.config = config; this.sourceImage = sourceImage; } /** * Generate WhatsApp-optimized images */ async generate(options = {}) { const { includeProfile = true, includeLinkPreview = true, title, description, template = 'basic' } = options; if (includeProfile) { await this.generateProfileImage(title, description, template); } if (includeLinkPreview) { await this.generateLinkPreviewImage(title, description, template); } } /** * Generate WhatsApp profile image (400x400) */ async generateProfileImage(title, description, template) { const processor = new image_processor_1.ImageProcessor(this.sourceImage); const outputPath = path_1.default.join(this.config.output.path, 'whatsapp-profile.png'); const socialFile = await processor.createSocialPreview({ width: image_processor_1.ImageSizes.messaging.whatsapp.width, height: image_processor_1.ImageSizes.messaging.whatsapp.height, title, description, template, background: this.config.backgroundColor }); const finalProcessor = new image_processor_1.ImageProcessor(socialFile); await finalProcessor.save(outputPath); await processor.cleanup(); } /** * Generate WhatsApp link preview image (1200x630) */ async generateLinkPreviewImage(title, description, template) { const processor = new image_processor_1.ImageProcessor(this.sourceImage); const outputPath = path_1.default.join(this.config.output.path, 'whatsapp-link.png'); const socialFile = await processor.createSocialPreview({ width: image_processor_1.ImageSizes.messaging.whatsappLink.width, height: image_processor_1.ImageSizes.messaging.whatsappLink.height, title, description, template, background: this.config.backgroundColor }); const finalProcessor = new image_processor_1.ImageProcessor(socialFile); await finalProcessor.save(outputPath); await processor.cleanup(); } /** * Generate standard WhatsApp sharing image (1200x630) */ async generateStandardImage(title, description, template) { const processor = new image_processor_1.ImageProcessor(this.sourceImage); const outputPath = path_1.default.join(this.config.output.path, 'whatsapp-share.png'); const socialFile = await processor.createSocialPreview({ width: image_processor_1.ImageSizes.messaging.whatsappLink.width, height: image_processor_1.ImageSizes.messaging.whatsappLink.height, title, description, template, background: this.config.backgroundColor }); const finalProcessor = new image_processor_1.ImageProcessor(socialFile); await finalProcessor.save(outputPath); await processor.cleanup(); } /** * Generate square WhatsApp image (1200x1200) */ async generateSquareImage(title, description, template) { const processor = new image_processor_1.ImageProcessor(this.sourceImage); const outputPath = path_1.default.join(this.config.output.path, 'whatsapp-square.png'); const socialFile = await processor.createSocialPreview({ width: 1200, height: 1200, title, description, template, background: this.config.backgroundColor }); const finalProcessor = new image_processor_1.ImageProcessor(socialFile); await finalProcessor.save(outputPath); await processor.cleanup(); } /** * Get HTML meta tags for WhatsApp */ getMetaTags() { const prefix = this.config.output.prefix || '/'; return [ `<meta property="og:image" content="${prefix}whatsapp-link.png">`, `<meta property="og:image:width" content="${image_processor_1.ImageSizes.messaging.whatsappLink.width}">`, `<meta property="og:image:height" content="${image_processor_1.ImageSizes.messaging.whatsappLink.height}">`, `<meta property="og:image:type" content="image/png">`, `<meta property="og:title" content="${this.config.appName}">`, `<meta property="og:description" content="${this.config.description || ''}">`, `<meta property="og:type" content="website">`, // WhatsApp-specific optimizations `<meta name="format-detection" content="telephone=no">`, `<meta name="apple-mobile-web-app-capable" content="yes">`, `<meta name="mobile-web-app-capable" content="yes">`, ]; } /** * Get Next.js metadata configuration for WhatsApp */ getNextMetadata() { const prefix = this.config.output.prefix || '/'; return { openGraph: { title: this.config.appName, description: this.config.description, images: [ { url: `${prefix}whatsapp-link.png`, width: image_processor_1.ImageSizes.messaging.whatsappLink.width, height: image_processor_1.ImageSizes.messaging.whatsappLink.height, alt: this.config.appName, } ], type: 'website', }, other: { 'format-detection': 'telephone=no', 'apple-mobile-web-app-capable': 'yes', 'mobile-web-app-capable': 'yes', }, }; } /** * Get list of generated files */ getGeneratedFiles() { return ['whatsapp-profile.png', 'whatsapp-link.png']; } } exports.WhatsAppGenerator = WhatsAppGenerator;