# Automatic Image Compression

## Overview
The application now automatically compresses and resizes images when uploading banners, products, and categories. This solves the "POST data is too large" error by reducing file sizes before saving.

## How It Works

### Banner Images
- **Max Upload Size**: 8MB
- **Auto Resize**: Max 1920x600px (maintains aspect ratio)
- **Auto Compress**: Saved as JPEG at 85% quality
- **Result**: Typically reduces to ~200-500KB

### Product Images
- **Max Upload Size**: 8MB
- **Auto Resize**: Max 800x800px
- **Auto Compress**: Saved as JPEG at 85% quality
- **Result**: Typically reduces to ~100-300KB

### Category Images
- **Max Upload Size**: 8MB
- **Auto Resize**: Max 400x400px
- **Auto Compress**: Saved as JPEG at 85% quality
- **Result**: Typically reduces to ~50-150KB

## Benefits

1. **No More Upload Errors**: Large images are automatically compressed
2. **Faster Page Loads**: Smaller images load faster
3. **Less Storage**: Reduced disk space usage
4. **Better Performance**: Optimized images improve site speed

## Technical Details

### Image Processing Service
Located at: `app/Services/ImageService.php`

**Methods:**
- `processBannerImage()` - Process banner images
- `processProductImage()` - Process product images
- `processCategoryImage()` - Process category images

### Compression Settings
- **Format**: All images converted to JPEG
- **Quality**: 85% (good balance between quality and size)
- **Resize**: Maintains aspect ratio, scales down if larger than max dimensions

### Library Used
- **Intervention Image v3** - Professional image manipulation library
- Automatically installed via Composer

## Usage

No changes needed! Just upload images normally:

1. Go to admin panel
2. Upload banner/product/category image
3. System automatically:
   - Resizes if too large
   - Compresses to reduce file size
   - Saves optimized version

## Troubleshooting

### Still Getting "POST data too large"?
1. Check PHP limits (should be at least 8MB):
   ```bash
   php -i | Select-String -Pattern "upload_max_filesize|post_max_size"
   ```

2. If limits are still 2MB/8MB, update php.ini:
   ```ini
   upload_max_filesize = 10M
   post_max_size = 12M
   ```

3. Restart WAMP after changes

### Image Quality Issues?
If images look too compressed, you can adjust quality in `ImageService.php`:
- Change `$quality` parameter (default: 85)
- Range: 1-100 (higher = better quality, larger file)

### Need Different Sizes?
Edit max dimensions in `BannerController.php`:
```php
$this->imageService->processBannerImage(
    $request->file('image'),
    1920, // max width - change this
    600,  // max height - change this
    85    // quality - change this
);
```

## File Size Comparison

**Before Compression:**
- Large banner: 5-10MB
- Product photo: 3-5MB
- Category icon: 1-2MB

**After Compression:**
- Banner: ~200-500KB (90-95% reduction)
- Product: ~100-300KB (90-95% reduction)
- Category: ~50-150KB (90-95% reduction)

## Notes

- Original files are not saved (only compressed version)
- All images converted to JPEG format
- Aspect ratio is always maintained
- Images larger than max dimensions are automatically resized

