# Asset Processing Scripts Reference

Complete reference for asset management, optimization, and integration scripts.

## integrate_assets.py

Main script for integrating assets from various sources.

### Basic Usage

```bash
# Integrate from local directory
python scripts/integrate_assets.py project-path \
  --source /path/to/images/ \
  --type images

# Integrate from cloud storage
python scripts/integrate_assets.py project-path \
  --source google-drive \
  --folder-id "1ABC...XYZ" \
  --auth-file credentials.json

# Integrate from design tools
python scripts/integrate_assets.py project-path \
  --source figma \
  --file-id "ABC123" \
  --access-token "figma-token" \
  --frames "Hero,Chart,Logo"
```

### Advanced Integration

```bash
# Integrate with optimization
python scripts/integrate_assets.py project-path \
  --source /images/ \
  --optimize \
  --generate-responsive \
  --quality 85 \
  --max-width 1920

# Integrate with AI processing
python scripts/integrate_assets.py project-path \
  --source /screenshots/ \
  --ai-enhance \
  --remove-backgrounds \
  --upscale-quality

# Batch integration from multiple sources
python scripts/integrate_assets.py project-path \
  --batch-config batch-sources.json \
  --parallel-processing \
  --progress-report
```

## Asset Source Integrations

### Cloud Storage Integration

#### Google Drive

```python
from asset_integrators import GoogleDriveIntegrator

integrator = GoogleDriveIntegrator(credentials_file='creds.json')

# Download folder contents
assets = integrator.download_folder(
    folder_id='1ABC...XYZ',
    file_types=['jpg', 'png', 'svg'],
    destination='assets/images/'
)

# Sync with Google Drive folder
integrator.setup_sync(
    folder_id='1ABC...XYZ',
    local_path='assets/',
    bidirectional=False,
    auto_optimize=True
)
```

#### Dropbox

```python
from asset_integrators import DropboxIntegrator

integrator = DropboxIntegrator(access_token='token')

assets = integrator.download_folder(
    folder_path='/Project Assets/',
    destination='assets/',
    include_shared=True
)
```

#### AWS S3

```python
from asset_integrators import S3Integrator

integrator = S3Integrator(aws_profile='default')

assets = integrator.sync_bucket(
    bucket_name='project-assets',
    prefix='slideshow/',
    destination='assets/',
    exclude_patterns=['*.tmp', '*.cache']
)
```

### Design Tool Integration

#### Figma Integration

```python
from asset_integrators import FigmaIntegrator

integrator = FigmaIntegrator(access_token='figma-token')

# Export specific frames
assets = integrator.export_frames(
    file_id='ABC123',
    frame_names=['Hero Image', 'Chart 1', 'Logo'],
    format='png',
    scale=2.0,
    destination='assets/images/'
)

# Export all frames from page
assets = integrator.export_page(
    file_id='ABC123',
    page_name='Slide Assets',
    format='svg',
    destination='assets/icons/'
)

# Setup auto-sync with Figma file
integrator.setup_webhook_sync(
    file_id='ABC123',
    webhook_url='http://localhost:8080/figma-update',
    auto_export=True
)
```

#### Adobe Creative Suite

```python
from asset_integrators import AdobeIntegrator

integrator = AdobeIntegrator(api_key='adobe-key')

# Export from Photoshop
assets = integrator.export_photoshop_layers(
    file_id='PSD123',
    layer_names=['Background', 'Text', 'Logo'],
    format='png',
    destination='assets/images/'
)

# Export from Illustrator
assets = integrator.export_illustrator_artboards(
    file_id='AI123',
    artboard_names=['Icon Set', 'Logo Variants'],
    format='svg',
    destination='assets/icons/'
)
```

#### Sketch Integration

```python
from asset_integrators import SketchIntegrator

integrator = SketchIntegrator()

# Export from Sketch Cloud
assets = integrator.export_sketch_cloud(
    document_id='sketch-doc-123',
    artboard_names=['Slide 1', 'Slide 2'],
    format='png',
    scale='2x'
)
```

## Asset Optimization

### optimize_assets.py

Comprehensive asset optimization for web delivery.

```bash
# Basic optimization
python scripts/optimize_assets.py project-path \
  --quality 85 \
  --max-width 1920 \
  --format webp

# Advanced optimization
python scripts/optimize_assets.py project-path \
  --progressive-jpeg \
  --generate-responsive \
  --sizes "480,768,1024,1920" \
  --lazy-loading-placeholders

# Optimization for specific deployment
python scripts/optimize_assets.py project-path \
  --target vercel \
  --cdn-optimization \
  --compression gzip
```

### Image Processing

```python
from asset_processors import ImageProcessor

processor = ImageProcessor()

# Basic image optimization
optimized = processor.optimize_image(
    input_path='assets/images/hero.jpg',
    output_path='assets/images/hero-optimized.jpg',
    quality=85,
    max_width=1920,
    format='webp'
)

# Generate responsive image set
responsive_set = processor.generate_responsive_set(
    input_path='assets/images/hero.jpg',
    output_prefix='assets/images/hero',
    sizes=[480, 768, 1024, 1920],
    formats=['webp', 'jpg']
)

# Batch process directory
processor.batch_optimize_directory(
    input_dir='assets/images/',
    output_dir='dist/assets/images/',
    settings={
        'quality': 85,
        'max_width': 1920,
        'generate_webp': True,
        'preserve_metadata': False
    }
)
```

### Advanced Image Processing

```python
# AI-powered image enhancement
enhanced = processor.ai_enhance_image(
    input_path='assets/images/low-quality.jpg',
    enhancements=['upscale', 'denoise', 'sharpen'],
    ai_model='real-esrgan'
)

# Background removal
no_bg = processor.remove_background(
    input_path='assets/images/product.jpg',
    ai_model='u2net',
    output_format='png'
)

# Smart cropping
cropped = processor.smart_crop(
    input_path='assets/images/landscape.jpg',
    target_aspect='16:9',
    focus_detection=True
)
```

## Asset Validation and Quality

### validate_assets.py

Validate asset quality and compliance.

```bash
# Validate asset quality
python scripts/validate_assets.py project-path \
  --check quality,format,size,accessibility

# Validate for web performance
python scripts/validate_assets.py project-path \
  --performance-check \
  --target-score 90 \
  --report performance-report.json

# Validate brand compliance
python scripts/validate_assets.py project-path \
  --brand ce \
  --check-colors \
  --check-usage-rights
```

### Asset Quality Checks

```python
from asset_validators import AssetValidator

validator = AssetValidator()

# Check image quality
quality_issues = validator.check_image_quality('assets/images/')
for issue in quality_issues:
    print(f"{issue.file}: {issue.issue_type} - {issue.description}")

# Check file sizes
size_issues = validator.check_file_sizes(
    directory='assets/',
    max_image_size='2MB',
    max_total_size='50MB'
)

# Check accessibility compliance
a11y_issues = validator.check_accessibility(
    assets_dir='assets/',
    checks=['alt_text', 'contrast', 'formats']
)
```

## Asset Transformation

### transform_assets.py

Transform assets for different contexts and platforms.

```bash
# Transform for different platforms
python scripts/transform_assets.py project-path \
  --platform web,mobile,print \
  --output-dir dist/platform-assets/

# Transform for brand variants
python scripts/transform_assets.py project-path \
  --brand-variants "ce,phat,client-brand" \
  --color-replacements brand-colors.json

# Transform with AI
python scripts/transform_assets.py project-path \
  --ai-transform \
  --style "corporate,professional" \
  --model stable-diffusion
```

### Asset Transformers

```python
from asset_transformers import AssetTransformer

transformer = AssetTransformer()

# Platform-specific transformations
web_assets = transformer.transform_for_web(
    input_dir='assets/',
    optimizations=['size', 'format', 'progressive'],
    target_quality=85
)

mobile_assets = transformer.transform_for_mobile(
    input_dir='assets/',
    max_size='1MB',
    retina_variants=True,
    dark_mode_variants=True
)

print_assets = transformer.transform_for_print(
    input_dir='assets/',
    dpi=300,
    color_space='CMYK',
    bleed_margin='0.125in'
)
```

## Content-Aware Asset Processing

### match_assets.py

Intelligently match assets to slide content.

```bash
# Auto-match assets to slides
python scripts/match_assets.py project-path \
  --content content/slides.json \
  --assets assets/images/ \
  --ai-matching

# Match with custom rules
python scripts/match_assets.py project-path \
  --matching-rules rules/asset-matching.json \
  --confidence-threshold 0.8

# Generate asset suggestions
python scripts/match_assets.py project-path \
  --suggest-assets \
  --stock-photo-integration \
  --unsplash-api-key "key"
```

### Intelligent Asset Matching

```python
from asset_matchers import ContentAssetMatcher

matcher = ContentAssetMatcher()

# Match assets to slide content
matches = matcher.match_assets_to_slides(
    slides_content=content['slides'],
    available_assets='assets/',
    ai_model='clip',
    confidence_threshold=0.7
)

for match in matches:
    print(f"Slide {match.slide_id}: {match.matched_asset}")
    print(f"Confidence: {match.confidence}")

# Generate missing asset suggestions
suggestions = matcher.suggest_missing_assets(
    slides_content=content['slides'],
    existing_assets='assets/',
    suggestion_sources=['unsplash', 'stock_photos']
)
```

## Asset Delivery and CDN

### deploy_assets.py

Deploy assets to CDN and configure delivery.

```bash
# Deploy to AWS CloudFront
python scripts/deploy_assets.py project-path \
  --cdn cloudfront \
  --bucket s3-bucket-name \
  --distribution-id ABCDEFG

# Deploy to Vercel
python scripts/deploy_assets.py project-path \
  --cdn vercel \
  --project-id vercel-project \
  --domain custom-domain.com

# Deploy with optimization
python scripts/deploy_assets.py project-path \
  --cdn netlify \
  --optimize-delivery \
  --compression brotli \
  --cache-headers
```

### CDN Configuration

```python
from asset_deployers import CDNDeployer

# AWS CloudFront deployment
cloudfront = CDNDeployer.cloudfront(
    bucket_name='slideshow-assets',
    distribution_config={
        'cache_behavior': 'aggressive',
        'compression': True,
        'security_headers': True
    }
)

# Deploy optimized assets
deployment = cloudfront.deploy_assets(
    local_path='dist/assets/',
    remote_prefix='slideshows/project-name/',
    optimization={
        'image_formats': ['webp', 'avif', 'jpg'],
        'responsive_images': True,
        'lazy_loading': True
    }
)

print(f"Assets deployed to: {deployment.base_url}")
print(f"Cache invalidated: {deployment.cache_invalidated}")
```

## Asset Analytics and Performance

### analyze_assets.py

Analyze asset usage and performance.

```bash
# Analyze asset usage
python scripts/analyze_assets.py project-path \
  --usage-analytics \
  --performance-metrics \
  --report assets-report.json

# Analyze for optimization opportunities
python scripts/analyze_assets.py project-path \
  --optimization-suggestions \
  --unused-assets \
  --size-analysis

# Real-time performance monitoring
python scripts/analyze_assets.py project-path \
  --monitor \
  --performance-budget "2MB" \
  --alert-threshold 90
```

### Asset Performance Monitoring

```python
from asset_analytics import AssetAnalyzer

analyzer = AssetAnalyzer(project_path)

# Analyze asset performance
performance = analyzer.analyze_performance()
print(f"Total asset size: {performance.total_size}")
print(f"Largest assets: {performance.largest_assets}")
print(f"Optimization potential: {performance.optimization_savings}")

# Monitor asset usage
usage_stats = analyzer.track_usage()
print(f"Most used assets: {usage_stats.most_used}")
print(f"Unused assets: {usage_stats.unused}")

# Performance recommendations
recommendations = analyzer.get_recommendations()
for rec in recommendations:
    print(f"{rec.type}: {rec.description}")
    print(f"Potential savings: {rec.savings}")
```

## Error Handling and Recovery

### Asset Processing Error Handling

```python
try:
    processor.optimize_image('corrupted.jpg')
except ImageCorruptedError as e:
    print(f"Image corrupted: {e.file_path}")
    # Attempt repair
    repaired = processor.attempt_repair(e.file_path)
    
except UnsupportedFormatError as e:
    print(f"Unsupported format: {e.format}")
    # Convert to supported format
    converted = processor.convert_format(e.file_path, 'jpg')
    
except InsufficientStorageError as e:
    print(f"Storage full: {e.required_space}")
    # Clean temporary files
    processor.cleanup_temp_files()
    
except NetworkTimeoutError as e:
    print(f"Network timeout downloading: {e.url}")
    # Retry with exponential backoff
    processor.retry_download(e.url, max_retries=3)
```

### Asset Recovery and Backup

```python
from asset_recovery import AssetBackupManager

backup_manager = AssetBackupManager(project_path)

# Create asset backup
backup_manager.create_backup(
    backup_name='pre-optimization',
    include_originals=True,
    compression=True
)

# Restore from backup
backup_manager.restore_backup(
    backup_name='pre-optimization',
    restore_path='assets-restored/',
    verify_integrity=True
)

# Monitor asset integrity
integrity_issues = backup_manager.verify_asset_integrity()
for issue in integrity_issues:
    print(f"Integrity issue: {issue.file_path}")
    backup_manager.restore_single_asset(issue.file_path)
```