UNPKG

pixel-forge

Version:

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

286 lines (285 loc) 11.3 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PlatformGenerator = void 0; const path_1 = __importDefault(require("path")); const image_processor_1 = require("../../core/image-processor"); class PlatformGenerator { constructor(sourceImage, config) { this.config = config; this.sourceImage = sourceImage; } /** * Generate all platform assets */ async generate(options = {}) { const { includeTikTok = true, includeYouTube = true, includePinterest = true, includeSnapchat = true, includeThreads = true, includeBluesky = true, includeMastodon = true } = options; // TikTok vertical format if (includeTikTok) { await this.generateTikTok(options); } // YouTube thumbnail format if (includeYouTube) { await this.generateYouTube(options); await this.generateYouTubeShorts(options); } // Pinterest formats if (includePinterest) { await this.generatePinterest(options); await this.generatePinterestSquare(options); } // Snapchat vertical format if (includeSnapchat) { await this.generateSnapchat(options); } // Emerging platforms if (includeThreads) { await this.generateThreads(options); } if (includeBluesky) { await this.generateBluesky(options); } if (includeMastodon) { await this.generateMastodon(options); } } /** * Generate TikTok format (1080x1920) */ async generateTikTok(options) { const { width, height } = image_processor_1.ImageSizes.social.tiktok; const outputPath = path_1.default.join(this.config.output.path, 'tiktok.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 || 'gradient', background: this.config.backgroundColor }); await processor.save(outputPath, { format: 'png', quality: this.config.output.quality }); } /** * Generate YouTube thumbnail (1280x720) */ async generateYouTube(options) { const { width, height } = image_processor_1.ImageSizes.social.youtubeThumbnail; const outputPath = path_1.default.join(this.config.output.path, 'youtube-thumbnail.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 YouTube Shorts (1080x1920) */ async generateYouTubeShorts(options) { const { width, height } = image_processor_1.ImageSizes.social.youtubeShorts; const outputPath = path_1.default.join(this.config.output.path, 'youtube-shorts.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 || 'gradient', background: this.config.backgroundColor }); await processor.save(outputPath, { format: 'png', quality: this.config.output.quality }); } /** * Generate Pinterest Pin (1000x1500) */ async generatePinterest(options) { const { width, height } = image_processor_1.ImageSizes.social.pinterestPin; const outputPath = path_1.default.join(this.config.output.path, 'pinterest-pin.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 || 'gradient', background: this.config.backgroundColor }); await processor.save(outputPath, { format: 'png', quality: this.config.output.quality }); } /** * Generate Pinterest Square (1000x1000) */ async generatePinterestSquare(options) { const { width, height } = image_processor_1.ImageSizes.social.pinterestSquare; const outputPath = path_1.default.join(this.config.output.path, 'pinterest-square.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 Snapchat format (1080x1920) */ async generateSnapchat(options) { const { width, height } = image_processor_1.ImageSizes.social.snapchat; const outputPath = path_1.default.join(this.config.output.path, 'snapchat.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 || 'gradient', background: this.config.backgroundColor }); await processor.save(outputPath, { format: 'png', quality: this.config.output.quality }); } /** * Generate Threads format (1080x1080) */ async generateThreads(options) { const { width, height } = image_processor_1.ImageSizes.social.threads; const outputPath = path_1.default.join(this.config.output.path, 'threads.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 Bluesky format (1200x630) */ async generateBluesky(options) { const { width, height } = image_processor_1.ImageSizes.social.bluesky; const outputPath = path_1.default.join(this.config.output.path, 'bluesky.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 Mastodon format (1200x630) */ async generateMastodon(options) { const { width, height } = image_processor_1.ImageSizes.social.mastodon; const outputPath = path_1.default.join(this.config.output.path, 'mastodon.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 additional platforms */ getMetaTags() { const { prefix = '/' } = this.config.output; return [ // TikTok `<meta property="og:image" content="${prefix}tiktok.png" />`, `<meta property="og:image:width" content="${image_processor_1.ImageSizes.social.tiktok.width}" />`, `<meta property="og:image:height" content="${image_processor_1.ImageSizes.social.tiktok.height}" />`, // YouTube `<meta property="og:video:tag" content="${this.config.appName}" />`, `<meta property="og:video:duration" content="0" />`, // Pinterest `<meta property="og:image" content="${prefix}pinterest-pin.png" />`, `<meta property="pinterest:description" content="${this.config.description}" />`, // Threads (Meta) `<meta property="fb:app_id" content="your-app-id" />`, // Bluesky `<meta property="bluesky:handle" content="${this.config.appName}" />`, // Mastodon `<meta property="fediverse:creator" content="${this.config.appName}" />` ]; } /** * Get Next.js metadata configuration for additional platforms */ getNextMetadata() { const { prefix = '/' } = this.config.output; return { openGraph: { images: [ { url: `${prefix}tiktok.png`, width: image_processor_1.ImageSizes.social.tiktok.width, height: image_processor_1.ImageSizes.social.tiktok.height }, { url: `${prefix}youtube-thumbnail.png`, width: image_processor_1.ImageSizes.social.youtubeThumbnail.width, height: image_processor_1.ImageSizes.social.youtubeThumbnail.height }, { url: `${prefix}pinterest-pin.png`, width: image_processor_1.ImageSizes.social.pinterestPin.width, height: image_processor_1.ImageSizes.social.pinterestPin.height } ] }, other: { 'pinterest:description': this.config.description, 'bluesky:handle': this.config.appName, 'fediverse:creator': this.config.appName } }; } } exports.PlatformGenerator = PlatformGenerator;