pixel-forge
Version:
A comprehensive generator for social media previews, favicons, and visual assets across all platforms
296 lines (295 loc) • 11.9 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MessagingGenerator = void 0;
const path_1 = __importDefault(require("path"));
const image_processor_1 = require("../../core/image-processor");
class MessagingGenerator {
constructor(sourceImage, config) {
this.config = config;
this.sourceImage = sourceImage;
}
/**
* Generate all messaging app assets
*/
async generate(options = {}) {
const { includeWhatsApp = true, includeDiscord = true, includeTelegram = true, includeSignal = true, includeSlack = true, includeWeChat = false, includeiMessage = true, includeAndroidRCS = true } = options;
// Standard messaging preview (1200x630) for most apps
await this.generateStandardPreview(options);
// WhatsApp specific sizes
if (includeWhatsApp) {
await this.generateWhatsApp(options);
}
// WeChat specific size
if (includeWeChat) {
await this.generateWeChat(options);
}
// Generate for other platforms that use standard size
if (includeDiscord) {
await this.generateDiscord(options);
}
if (includeTelegram) {
await this.generateTelegram(options);
}
if (includeSignal) {
await this.generateSignal(options);
}
if (includeSlack) {
await this.generateSlack(options);
}
if (includeiMessage) {
await this.generateiMessage(options);
}
if (includeAndroidRCS) {
await this.generateAndroidRCS(options);
}
}
/**
* Generate standard messaging preview (1200x630)
* Used by most messaging apps
*/
async generateStandardPreview(options) {
const { width, height } = image_processor_1.ImageSizes.messaging.standard;
const outputPath = path_1.default.join(this.config.output.path, 'messaging-standard.png');
const processor = new image_processor_1.ImageProcessor(this.sourceImage);
processor.createSocialPreview({
width,
height,
title: options.title || this.config.appName,
description: options.description,
template: options.template,
background: this.config.backgroundColor
});
await processor.save(outputPath, {
format: 'png',
quality: this.config.output.quality
});
}
/**
* Generate WhatsApp preview (400x400 for profile + 1200x630 for links)
*/
async generateWhatsApp(options) {
// Square format for WhatsApp profile/status
const { width: squareWidth, height: squareHeight } = image_processor_1.ImageSizes.messaging.whatsapp;
const squareOutputPath = path_1.default.join(this.config.output.path, 'whatsapp-square.png');
const squareProcessor = new image_processor_1.ImageProcessor(this.sourceImage);
squareProcessor.createSocialPreview({
width: squareWidth,
height: squareHeight,
title: options.title || this.config.appName,
description: options.description,
template: options.template || 'basic',
background: this.config.backgroundColor
});
await squareProcessor.save(squareOutputPath, {
format: 'png',
quality: this.config.output.quality
});
// Link preview format
const { width: linkWidth, height: linkHeight } = image_processor_1.ImageSizes.messaging.whatsappLink;
const linkOutputPath = path_1.default.join(this.config.output.path, 'whatsapp-link.png');
const linkProcessor = new image_processor_1.ImageProcessor(this.sourceImage);
linkProcessor.createSocialPreview({
width: linkWidth,
height: linkHeight,
title: options.title || this.config.appName,
description: options.description,
template: options.template,
background: this.config.backgroundColor
});
await linkProcessor.save(linkOutputPath, {
format: 'png',
quality: this.config.output.quality
});
}
/**
* Generate WeChat preview (500x400)
*/
async generateWeChat(options) {
const { width, height } = image_processor_1.ImageSizes.messaging.wechat;
const outputPath = path_1.default.join(this.config.output.path, 'wechat.png');
const processor = new image_processor_1.ImageProcessor(this.sourceImage);
processor.createSocialPreview({
width,
height,
title: options.title || this.config.appName,
description: options.description,
template: options.template,
background: this.config.backgroundColor
});
await processor.save(outputPath, {
format: 'png',
quality: this.config.output.quality
});
}
/**
* Generate Discord preview (1200x630)
*/
async generateDiscord(options) {
const { width, height } = image_processor_1.ImageSizes.messaging.discord;
const outputPath = path_1.default.join(this.config.output.path, 'discord.png');
const processor = new image_processor_1.ImageProcessor(this.sourceImage);
processor.createSocialPreview({
width,
height,
title: options.title || this.config.appName,
description: options.description,
template: options.template,
background: this.config.backgroundColor
});
await processor.save(outputPath, {
format: 'png',
quality: this.config.output.quality
});
}
/**
* Generate Telegram preview (1200x630)
*/
async generateTelegram(options) {
const { width, height } = image_processor_1.ImageSizes.messaging.telegram;
const outputPath = path_1.default.join(this.config.output.path, 'telegram.png');
const processor = new image_processor_1.ImageProcessor(this.sourceImage);
processor.createSocialPreview({
width,
height,
title: options.title || this.config.appName,
description: options.description,
template: options.template,
background: this.config.backgroundColor
});
await processor.save(outputPath, {
format: 'png',
quality: this.config.output.quality
});
}
/**
* Generate Signal preview (1200x630)
*/
async generateSignal(options) {
const { width, height } = image_processor_1.ImageSizes.messaging.signal;
const outputPath = path_1.default.join(this.config.output.path, 'signal.png');
const processor = new image_processor_1.ImageProcessor(this.sourceImage);
processor.createSocialPreview({
width,
height,
title: options.title || this.config.appName,
description: options.description,
template: options.template,
background: this.config.backgroundColor
});
await processor.save(outputPath, {
format: 'png',
quality: this.config.output.quality
});
}
/**
* Generate Slack preview (1200x630)
*/
async generateSlack(options) {
const { width, height } = image_processor_1.ImageSizes.messaging.slack;
const outputPath = path_1.default.join(this.config.output.path, 'slack.png');
const processor = new image_processor_1.ImageProcessor(this.sourceImage);
processor.createSocialPreview({
width,
height,
title: options.title || this.config.appName,
description: options.description,
template: options.template,
background: this.config.backgroundColor
});
await processor.save(outputPath, {
format: 'png',
quality: this.config.output.quality
});
}
/**
* Generate iMessage preview (1200x630)
*/
async generateiMessage(options) {
const { width, height } = image_processor_1.ImageSizes.messaging.imessage;
const outputPath = path_1.default.join(this.config.output.path, 'imessage.png');
const processor = new image_processor_1.ImageProcessor(this.sourceImage);
processor.createSocialPreview({
width,
height,
title: options.title || this.config.appName,
description: options.description,
template: options.template,
background: this.config.backgroundColor
});
await processor.save(outputPath, {
format: 'png',
quality: this.config.output.quality
});
}
/**
* Generate Android RCS preview (1200x630)
*/
async generateAndroidRCS(options) {
const { width, height } = image_processor_1.ImageSizes.messaging.androidRcs;
const outputPath = path_1.default.join(this.config.output.path, 'android-rcs.png');
const processor = new image_processor_1.ImageProcessor(this.sourceImage);
processor.createSocialPreview({
width,
height,
title: options.title || this.config.appName,
description: options.description,
template: options.template,
background: this.config.backgroundColor
});
await processor.save(outputPath, {
format: 'png',
quality: this.config.output.quality
});
}
/**
* Get HTML meta tags for messaging apps
*/
getMetaTags() {
const { prefix = '/' } = this.config.output;
return [
// Standard OpenGraph for most messaging apps
`<meta property="og:image" content="${prefix}messaging-standard.png" />`,
`<meta property="og:image:width" content="${image_processor_1.ImageSizes.messaging.standard.width}" />`,
`<meta property="og:image:height" content="${image_processor_1.ImageSizes.messaging.standard.height}" />`,
// WhatsApp specific
`<meta property="og:image:alt" content="WhatsApp preview" />`,
// iMessage/Apple
`<meta property="apple-mobile-web-app-capable" content="yes" />`,
`<meta property="apple-mobile-web-app-status-bar-style" content="default" />`,
// Discord
`<meta name="theme-color" content="${this.config.backgroundColor}" />`,
// Telegram
`<meta property="telegram:channel" content="${this.config.appName}" />`
];
}
/**
* Get Next.js metadata configuration for messaging
*/
getNextMetadata() {
const { prefix = '/' } = this.config.output;
return {
openGraph: {
images: [
{
url: `${prefix}messaging-standard.png`,
width: image_processor_1.ImageSizes.messaging.standard.width,
height: image_processor_1.ImageSizes.messaging.standard.height
},
{
url: `${prefix}whatsapp-link.png`,
width: image_processor_1.ImageSizes.messaging.whatsappLink.width,
height: image_processor_1.ImageSizes.messaging.whatsappLink.height
}
]
},
other: {
'apple-mobile-web-app-capable': 'yes',
'apple-mobile-web-app-status-bar-style': 'default'
}
};
}
}
exports.MessagingGenerator = MessagingGenerator;