# Asset API Reference

The Asset API handles image and media integration from any source into slideshow projects.

## Asset Types

### Images
- **Supported formats**: JPG, PNG, WebP, SVG
- **Location**: `assets/images/`
- **Optimization**: Automatic compression and responsive variants
- **Usage**: Slide backgrounds, content images, hero images

### Icons  
- **Supported formats**: SVG, PNG (with transparency)
- **Location**: `assets/icons/`
- **Usage**: UI elements, bullet points, brand elements

### Media
- **Supported formats**: MP4, WebM (video), MP3, WAV (audio)
- **Location**: `assets/media/`
- **Usage**: Background videos, audio narration

## Python API

### Basic Usage

```python
from asset_api import AssetAPI

# Initialize
api = AssetAPI('/path/to/project')

# Add image from local file
image_path = api.add_image('/source/image.jpg', 'hero-image.jpg')
# Returns: "assets/images/hero-image.jpg"

# Add image from URL
image_path = api.add_image_from_url('https://example.com/image.png', 'remote-image.png')

# Add icon
icon_path = api.add_icon('/source/icon.svg', 'brand-logo.svg')

# Add media file
media_path = api.add_media('/source/video.mp4', 'background-video.mp4')
```

### Advanced Methods

```python
# Batch import from directory
api.import_directory('/source/images', asset_type='images')

# Import with automatic optimization
api.add_optimized_image('/source/large-image.jpg', 'optimized.jpg', 
                       max_width=1920, quality=85)

# Generate responsive variants
api.generate_responsive_set('/source/hero.jpg', 'hero', 
                           sizes=[480, 768, 1024, 1920])
# Creates: hero-480.jpg, hero-768.jpg, hero-1024.jpg, hero-1920.jpg

# Add with metadata
api.add_image('/source/chart.png', 'revenue-chart.png',
              metadata={
                  'title': 'Revenue Growth Chart',
                  'alt': 'Bar chart showing 300% revenue growth',
                  'caption': 'Q4 2025 revenue exceeded projections'
              })
```

## CLI Usage

### Basic Commands

```bash
# Add single image
python scripts/apis/asset_api.py project-path add-image /source/image.jpg hero.jpg

# Add from URL
python scripts/apis/asset_api.py project-path add-url https://example.com/image.png remote.png

# Import directory
python scripts/apis/asset_api.py project-path import-dir /source/images/

# Optimize existing assets
python scripts/apis/asset_api.py project-path optimize --quality 80 --max-width 1920
```

### Batch Operations

```bash
# Import from multiple sources
python scripts/apis/asset_api.py project-path batch-import \
  --chat-images /chat/export/images/ \
  --figma-exports /figma/exports/ \
  --stock-photos /downloads/

# Sync with external source
python scripts/apis/asset_api.py project-path sync \
  --source google-drive \
  --folder-id "1ABC...XYZ" \
  --auth-file credentials.json
```

## Integration Sources

### Chat/Discord Images

Import images from chat exports or Discord channels:

```python
# From Discord channel export
api.import_discord_channel('/path/to/discord-export/', 
                          channel_name='project-images')

# From Slack export
api.import_slack_workspace('/path/to/slack-export/',
                          channel_name='design-assets')
```

### Cloud Storage

```python
# Google Drive integration
api.sync_google_drive(folder_id='1ABC...XYZ', 
                     credentials_file='creds.json')

# Dropbox integration  
api.sync_dropbox(folder_path='/Project Images/',
                access_token='token')

# AWS S3 integration
api.sync_s3(bucket_name='project-assets',
           prefix='slideshow/',
           aws_profile='default')
```

### Design Tools

```python
# Figma integration
api.import_figma_exports(file_id='ABC123',
                        access_token='token',
                        frame_names=['Hero', 'Chart', 'Logo'])

# Adobe Creative Cloud
api.import_adobe_cc(project_id='123',
                   asset_types=['images', 'logos'])
```

### Stock Photo Services

```python
# Unsplash integration
api.add_unsplash_image(search_query='business meeting',
                      filename='team-photo.jpg',
                      api_key='unsplash_key')

# Getty Images integration
api.add_getty_image(image_id='123456789',
                   filename='corporate.jpg', 
                   api_key='getty_key')
```

## Asset Processing

### Automatic Optimization

All images are automatically processed for web delivery:

```python
# Configure optimization settings
api.set_optimization_settings({
    'jpeg_quality': 85,
    'png_compression': 9,
    'webp_quality': 80,
    'max_width': 1920,
    'max_height': 1080,
    'auto_webp': True,  # Generate WebP variants
    'auto_responsive': True  # Generate multiple sizes
})
```

### Image Variants

The system automatically generates optimal variants:

```
assets/images/
├── hero.jpg           # Original
├── hero-480w.jpg      # Mobile
├── hero-768w.jpg      # Tablet  
├── hero-1024w.jpg     # Desktop
├── hero-1920w.jpg     # Large screens
├── hero.webp          # WebP format
└── hero-480w.webp     # WebP mobile
```

### Metadata Management

```python
# Set image metadata
api.set_image_metadata('hero.jpg', {
    'title': 'Company Team Photo',
    'alt': 'Team of 12 people in modern office',
    'caption': 'Our growing team in the new headquarters',
    'photographer': 'Jane Smith',
    'usage_rights': 'royalty-free',
    'tags': ['team', 'office', 'corporate']
})

# Get image info
info = api.get_image_info('hero.jpg')
print(info['dimensions'])  # (1920, 1080)
print(info['file_size'])   # 245KB
print(info['format'])      # JPEG
```

## Content Integration

### Automatic Slide Updates

When adding assets, automatically update content references:

```python
# Add image and update slide
image_path = api.add_image('/source/chart.png', 'revenue-chart.png')
api.update_slide_image('slide-5', image_path, 
                      alt='Revenue growth chart',
                      caption='300% growth in Q4 2025')
```

### Asset Collections

Organize assets by slide or theme:

```python
# Create asset collection
collection = api.create_collection('financial-charts')
collection.add_image('revenue-chart.png')
collection.add_image('profit-margins.png')
collection.add_image('market-share.png')

# Apply collection to slides
api.apply_collection_to_slides(collection, ['slide-5', 'slide-6', 'slide-7'])
```

## Performance Optimization

### Lazy Loading

Automatically implement lazy loading for large presentations:

```python
# Configure lazy loading
api.configure_lazy_loading({
    'enabled': True,
    'threshold': '50px',  # Load when 50px from viewport
    'placeholder': 'blur',  # Blur placeholder
    'fade_in': True  # Fade in animation
})
```

### CDN Integration

Automatically upload optimized assets to CDN:

```python
# Configure CDN
api.configure_cdn({
    'provider': 'cloudfront',
    'bucket': 's3-bucket-name',
    'domain': 'cdn.example.com',
    'auto_upload': True
})
```

### Preloading

Intelligently preload critical images:

```python
# Mark critical assets for preloading
api.mark_critical(['hero.jpg', 'logo.svg'])  # Preload immediately
api.mark_priority(['chart1.png', 'chart2.png'])  # Preload after critical
```

## Error Handling

```python
try:
    api.add_image('invalid-path.jpg')
except FileNotFoundError:
    print("Source file not found")
    
try:
    api.add_image_from_url('http://invalid-url.com/image.jpg')
except AssetDownloadError as e:
    print(f"Failed to download: {e.status_code} - {e.message}")
    
try:
    api.optimize_image('corrupted.jpg')
except ImageProcessingError as e:
    print(f"Processing failed: {e.message}")
```

## Asset Validation

### Format Validation

```python
# Check supported formats
supported = api.get_supported_formats()
print(supported['images'])  # ['jpg', 'png', 'webp', 'svg']

# Validate before adding
if api.validate_image_format('/source/file.bmp'):
    api.add_image('/source/file.bmp')
else:
    print("Unsupported format")
```

### Size Limits

```python
# Configure size limits
api.set_size_limits({
    'max_file_size': '10MB',
    'max_dimensions': (4096, 4096),
    'min_dimensions': (100, 100)
})

# Check file before adding
if api.validate_file_size('/source/huge-image.jpg'):
    api.add_image('/source/huge-image.jpg')
```

### Content Validation

```python
# Ensure images are not corrupted
api.validate_image_integrity('suspicious-image.jpg')

# Check for inappropriate content (if API key provided)
api.validate_content_safety('user-uploaded.jpg', api_key='moderation_key')
```