Overview
The Image Processing API provides comprehensive image handling capabilities including compression, resizing, validation, and variant generation for different use cases across the platform. Location:convex/shared/imageProcessing.ts
Smart Compression
Automatic image compression with quality optimization
Size Validation
Validates images against type-specific size limits
Variant Generation
Creates multiple image sizes for responsive display
Format Optimization
Converts images to optimized JPEG format
Image Size Limits
The system enforces different size limits based on image type:Avatar Images
Avatar Images
- Max Size: 2MB
- Max Dimensions: 512x512px
- Use Case: User profile pictures
Store Logo
Store Logo
- Max Size: 2MB
- Max Dimensions: 800x800px
- Use Case: Store branding and identification
Store Cover
Store Cover
- Max Size: 5MB
- Max Dimensions: 1920x1080px
- Use Case: Store banner images
Trade License
Trade License
- Max Size: 10MB
- Max Dimensions: 2048x2048px
- Use Case: Document verification
Product Images
Product Images
- Max Size: 5MB
- Max Dimensions: 1920x1920px
- Use Case: Product photos (primary and additional)
Review Photos
Review Photos
- Max Size: 5MB
- Max Dimensions: 1920x1920px
- Use Case: Customer review images
Chat Images
Chat Images
- Max Size: 5MB
- Max Dimensions: 1920x1920px
- Use Case: Images shared in conversations
Process Image
Process and optimize an uploaded image with automatic compression and resizing.Storage ID of the uploaded image
imageType
'avatar' | 'storeLogo' | 'storeCover' | 'tradeLicense' | 'productPrimary' | 'productAdditional' | 'reviewPhoto' | 'chatImage'
required
Type of image being processed
JPEG quality (1-100, default: 80)
This function processes images in a Node.js environment using Jimp for image manipulation. The processed image is stored as a new file and the original is preserved.
Validate Image Upload
Validate an uploaded image before processing to ensure it meets size and dimension requirements.Storage ID of the uploaded image
imageType
'avatar' | 'storeLogo' | 'storeCover' | 'tradeLicense' | 'productPrimary' | 'productAdditional' | 'reviewPhoto' | 'chatImage'
required
Type of image being validated
Create Image Variants
Create multiple image variants (thumbnails, medium, large) for responsive display.Storage ID of the source image
Array of variant configurations
Name for the variant (e.g., “thumbnail”, “medium”, “large”)
Target width in pixels
Target height in pixels (optional - maintains aspect ratio if not provided)
JPEG quality for this variant (default: 80)
Complete Image Upload Flow
Here’s a complete example of uploading and processing an image:Image Type Guidelines
Avatar Images
Avatar Images
Best Practices:
- Use square aspect ratio (1:1)
- High quality (90+) for user-facing images
- Consider adding border radius in UI
- Customer profile pictures
- Store owner avatars
Product Images
Product Images
Best Practices:
- Use square or 4:3 aspect ratio
- Good lighting and clear product visibility
- Multiple angles for better representation
- Product catalog images
- Featured product displays
Store Branding
Store Branding
Best Practices:
- Logo: Simple, recognizable at small sizes
- Cover: Wide format, represents store theme
- Consistent with brand colors
- Store identification
- Marketing materials
Document Images
Document Images
Best Practices:
- High resolution for text readability
- Good contrast and lighting
- Full document visible in frame
- Trade license verification
- Identity documents
Error Handling
Image too large
Image too large
Status Code:
400Invalid image format
Invalid image format
Status Code:
400Processing failed
Processing failed
Status Code:
500Storage not found
Storage not found
Status Code:
404Performance Tips
Compression Quality
Use quality 70-80 for thumbnails, 85-90 for main images
Variant Sizes
Create variants only for sizes you actually use
Batch Processing
Process multiple images in parallel when possible
Storage Cleanup
Clean up original files after processing if not needed
All image processing functions run in a Node.js environment and may take several seconds to complete for large images. Consider showing loading indicators to users.
