Add smart presets for common use cases
This commit is contained in:
128
frontend/src/lib/presets.ts
Normal file
128
frontend/src/lib/presets.ts
Normal file
@@ -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
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user