From 4f694b10241684d7e890bc72441cae5bb9254323 Mon Sep 17 00:00:00 2001 From: jason Date: Sun, 8 Mar 2026 17:05:53 -0500 Subject: [PATCH] Add smart presets for common use cases --- frontend/src/lib/presets.ts | 128 ++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 frontend/src/lib/presets.ts diff --git a/frontend/src/lib/presets.ts b/frontend/src/lib/presets.ts new file mode 100644 index 0000000..e169a14 --- /dev/null +++ b/frontend/src/lib/presets.ts @@ -0,0 +1,128 @@ +/** + * Smart Presets for common image transformation use cases + */ + +export interface Preset { + name: string; + description: string; + icon: string; + width?: number; + height?: number; + quality: number; + format: 'png' | 'webp' | 'jpeg'; + fit: 'inside' | 'cover'; +} + +export const PRESETS: Preset[] = [ + { + name: 'Web Thumbnail', + description: 'Small, optimized for web (300x300)', + icon: '🖼️', + width: 300, + height: 300, + quality: 75, + format: 'webp', + fit: 'cover' + }, + { + name: 'Social Media', + description: 'Open Graph image (1200x630)', + icon: '📱', + width: 1200, + height: 630, + quality: 85, + format: 'png', + fit: 'cover' + }, + { + name: 'Profile Picture', + description: 'Square avatar (400x400)', + icon: '👤', + width: 400, + height: 400, + quality: 85, + format: 'png', + fit: 'cover' + }, + { + name: 'Email Friendly', + description: 'Compressed for email', + icon: '📧', + width: 600, + quality: 70, + format: 'jpeg', + fit: 'inside' + }, + { + name: 'HD Quality', + description: 'High resolution (1920px wide)', + icon: '⭐', + width: 1920, + quality: 90, + format: 'png', + fit: 'inside' + }, + { + name: 'Retina @2x', + description: 'Double size for high-DPI', + icon: '🔍', + quality: 85, + format: 'png', + fit: 'inside' + }, + { + name: 'Icon Small', + description: 'Tiny icon (64x64)', + icon: '🔷', + width: 64, + height: 64, + quality: 100, + format: 'png', + fit: 'cover' + }, + { + name: 'Icon Large', + description: 'Large icon (256x256)', + icon: '🔶', + width: 256, + height: 256, + quality: 100, + format: 'png', + fit: 'cover' + } +]; + +/** + * Apply a preset to current settings + * For Retina @2x, we double the current dimensions + */ +export function applyPreset( + preset: Preset, + currentWidth?: number | null, + currentHeight?: number | null +): { + width: number | null; + height: number | null; + quality: number; + format: 'png' | 'webp' | 'jpeg'; + fit: 'inside' | 'cover'; +} { + // Special handling for Retina @2x preset + if (preset.name === 'Retina @2x') { + return { + width: currentWidth ? currentWidth * 2 : null, + height: currentHeight ? currentHeight * 2 : null, + quality: preset.quality, + format: preset.format, + fit: preset.fit + }; + } + + return { + width: preset.width || null, + height: preset.height || null, + quality: preset.quality, + format: preset.format, + fit: preset.fit + }; +} \ No newline at end of file