> For the complete documentation index, see [llms.txt](https://mostafaznv.gitbook.io/larupload/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mostafaznv.gitbook.io/larupload/advanced-usage/attachment/optimize-image.md).

# Optimize Image

The `optimizeImage` function allows you to enable or disable the image optimization feature for uploaded images. When enabled, the uploaded image will be optimized using the `spatie/image-optimizer` package, which can reduce the file size of the image without affecting its quality.

By default, image optimization is disabled in Larupload. You can enable it by calling the `optimizeImage` function and passing `true` as the argument, like this:

```php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Mostafaznv\Larupload\Enums\LaruploadSecureIdsMethod;
use Mostafaznv\Larupload\Storage\Attachment;
use Mostafaznv\Larupload\Traits\Larupload;

class Media extends Model
{
    use Larupload;

    public function attachments(): array
    {
        return [
            Attachment::make('file')->optimizeImage(ture)
        ];
    }
}
```
