> ## Documentation Index
> Fetch the complete documentation index at: https://flex-fields.bjanczak.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Examples target Filament 5. Verify optional dependencies before configuring integrations.
> Upload transfer completion, permanent storage and record acceptance are separate milestones. Native and Spatie image conversions retain the original.

# Image editor

> Add cropping, rotation, image adjustments and controlled replacement to FLEX uploads, with disk storage or Spatie Media Library.

Let people crop and adjust an image before saving it. The editor works with newly uploaded images and existing images owned by the field. It reads the original image, even when the upload list displays a smaller conversion.

## Enable the editor

```php theme={"theme":{"light":"github-light","dark":"github-dark"}}
use Bjanczak\FilamentFlexFields\Filament\Forms\Components\FlexImageUpload;

FlexImageUpload::make('photo')
    ->imagesOnly()
    ->imageEditor()
    ->disk('public')
    ->directory('photos')
    ->maxSize(5120);
```

The image's actions include **Edit image**. The user opens the editor, makes changes and applies them. FLEX creates a replacement upload; the usual form save stores it using the field's existing persistence settings. Closing the editor without applying discards its unsaved editing changes.

No extra JavaScript installation or application build is needed. The package ships the editor assets; its crop geometry module loads when editing is opened. Ordinary upload fields do not initialize an image editor.

## What users can change

The **Crop** view provides a movable crop area, free cropping, configured aspect ratios, rotation in 90° steps, horizontal/vertical flipping and reset. Scrolling over the image zooms the crop workspace.

The adjustment controls include brightness, warmth, contrast, exposure, highlights, shadows, fade, saturation, vibrance, clarity, sharpness and vignette. Adjustment values apply to the exported image, rather than adding a CSS filter to its saved preview. The editor provides its own controls; there is currently no PHP option for supplying an arbitrary list of adjustment tools or an export-quality slider.

## Offer useful aspect ratios

```php theme={"theme":{"light":"github-light","dark":"github-dark"}}
FlexImageUpload::make('cover')
    ->imagesOnly()
    ->imageEditor()
    ->imageEditorAspectRatioOptions(['16:9', '4:3', '1:1'])
    ->disk('public')
    ->directory('covers');
```

`imageEditorAspectRatioOptions()` is the current method name. The older `imageEditorAspectRatios()` method is an alias. An explicitly enabled rectangular editor also offers **Free** cropping; a list of suggested ratios is not a server-side dimension rule. Use the field's [image validation rules](https://flex-fields.bjanczak.com/docs/file-upload-api.md) when the saved image must meet exact requirements.

### Open cropping when a selected image has the wrong ratio

```php theme={"theme":{"light":"github-light","dark":"github-dark"}}
FlexImageUpload::make('banner')
    ->imagesOnly()
    ->imageEditor()
    ->imageCropAspectRatio('16:9')
    ->automaticallyOpenImageEditorForAspectRatio()
    ->imageEditorAspectRatioOptions(['16:9'])
    ->imageResizeTargetWidth('1600')
    ->imageResizeTargetHeight('900');
```

`imageCropAspectRatio()` sets the target used by automatic image preparation. `automaticallyOpenImageEditorForAspectRatio()` opens guided cropping when the selected image does not match that ratio. Keep server-side file type, byte and dimension rules appropriate to your application; browser editing is not a substitute for validation.

## Configure crop geometry

```php theme={"theme":{"light":"github-light","dark":"github-dark"}}
FlexImageUpload::make('photo')
    ->imagesOnly()
    ->imageEditor()
    ->imageEditorViewportWidth(720)
    ->imageEditorViewportHeight(480)
    ->imageEditorMode(1)
    ->imageEditorEmptyFillColor('#ffffff');
```

| Method | Purpose |
| - | - |
| `imageEditorViewportWidth()` / `imageEditorViewportHeight()` | Initial crop geometry when no target crop or resize setting overrides it; these are not the dialog's CSS width and height |
| `imageEditorMode(1)` | Keep the crop box within the image canvas; the default mode |
| `imageEditorMode(2)` | Also constrain the canvas to cover the editor container's minimum fitted area |
| `imageEditorMode(3)` | Constrain the canvas to fill the editor container |
| `imageEditorEmptyFillColor()` | Color used for empty exported canvas areas; null uses transparent fill |
| `imageEditor(false)` | Remove the explicitly enabled full editor |

Modes `1`, `2` and `3` are supported. Target resize dimensions or `imageCropAspectRatio()` can determine the initial viewport ahead of the explicit viewport methods.

## Circular images and inline avatars

For the full editor with a circular crop and a transparent PNG result:

```php theme={"theme":{"light":"github-light","dark":"github-dark"}}
FlexImageUpload::make('avatar')
    ->imagesOnly()
    ->avatar()
    ->imageEditor()
    ->circleCropper()
    ->disk('public')
    ->directory('avatars');
```

The avatar layout also has its own inline photo adjustment flow. That inline flow and the full Crop/Adjust editor are different interfaces. To offer selectable characters and optional cropping of a gallery choice, configure the [avatar gallery](https://flex-fields.bjanczak.com/docs/file-upload-avatar-gallery.md):

```php theme={"theme":{"light":"github-light","dark":"github-dark"}}
use Bjanczak\FilamentFlexFields\Support\FileUpload\Avatar\AvatarCollection;
use Bjanczak\FilamentFlexFields\Support\FileUpload\Avatar\AvatarGallery;

FlexImageUpload::make('avatar')
    ->imagesOnly()
    ->avatar()
    ->avatarGallery(new AvatarGallery(
        collections: [AvatarCollection::flexPack()],
        cropOnSelect: true,
    ));
```

## Resize the image sent for upload

```php theme={"theme":{"light":"github-light","dark":"github-dark"}}
FlexImageUpload::make('photo')
    ->imagesOnly()
    ->imageEditor()
    ->imageResizeMode('cover')
    ->imageResizeTargetWidth('1200')
    ->imageResizeTargetHeight('800')
    ->imageResizeUpscale(false)
    ->maxSize(5120);
```

Automatic resize modes are `cover`, `contain` and `force`. Use both target dimensions for an explicit rectangular target; `force` can change proportions. `imageResizeUpscale(false)` prevents automatic resize preparation from enlarging smaller sources. Applied editor output uses configured target dimensions when present.

Browser editing and resize settings alter the file supplied to the upload. Named server conversions create separate derivatives **after storage**. Use server conversions when you need to keep the uploaded image and produce thumbnails or delivery sizes from it.

## Create thumbnails from the edited result

```php theme={"theme":{"light":"github-light","dark":"github-dark"}}
use Bjanczak\FilamentFlexFields\Support\Media\Images\ImageConversion;
use Bjanczak\FilamentFlexFields\Support\Media\Images\ImageFit;
use Bjanczak\FilamentFlexFields\Support\Media\Images\ImageFormat;

FlexImageUpload::make('photos')
    ->imagesOnly()
    ->multiple()
    ->uploadLayout('grid')
    ->imageEditor()
    ->disk('public')
    ->directory('photos')
    ->imageConversions([
        new ImageConversion(
            name: 'thumb', width: 320, height: 320,
            fit: ImageFit::Cover, format: ImageFormat::Webp,
        ),
        new ImageConversion(name: 'large', width: 1600, format: ImageFormat::Webp),
    ])
    ->previewConversion('thumb')
    ->queueImageConversions();
```

The saved replacement becomes the source for its new conversions. Queued conversion work needs a running worker. While a conversion is pending, the original is the preview fallback. See [background processing](https://flex-fields.bjanczak.com/docs/file-upload-images-and-sources.md#background-image-processing) for queue configuration and status updates.

## Use Spatie Media Library

```php theme={"theme":{"light":"github-light","dark":"github-dark"}}
use Bjanczak\FilamentFlexFields\Filament\Forms\Components\Spatie\FlexSpatieMediaLibraryFileUpload;

FlexSpatieMediaLibraryFileUpload::make('photos')
    ->imagesOnly()
    ->multiple()
    ->collection('photos')
    ->imageEditor()
    ->imageEditorAspectRatioOptions(['4:3', '1:1'])
    ->conversion('thumb');
```

Your model must implement Media Library's integration and define the `photos` collection and `thumb` conversion. Define queued conversions on the model with Spatie's conversion API. Do not add the disk uploader's `imageConversions()` as a second conversion engine. Applying an edit updates the form's draft association; normal form saving persists the replacement through the Spatie adapter.

## Bound image memory and output size

```php theme={"theme":{"light":"github-light","dark":"github-dark"}}
use Bjanczak\FilamentFlexFields\Support\Media\Images\ImageLimits;

FlexImageUpload::make('photo')
    ->imagesOnly()
    ->imageEditor()
    ->maxSize(5120)
    ->imageLimits(new ImageLimits(
        sourcePixels: 8_000_000,
        outputPixels: 4_000_000,
        variants: 4,
        workingBytes: 256 * 1024 * 1024,
    ));
```

The editor checks decoded source and output pixel counts. Its effective pixel limits also account for the configured working-memory allowance, so increasing a pixel count alone does not guarantee admission. File size limits and final server validation still apply. A small compressed file can decode to a large image; configure both byte and pixel budgets.

## SVG and output formats

SVG editing rasterizes the image; the resulting upload is PNG, not an editable SVG document. Enable the confirmation when people need a warning before this change:

```php theme={"theme":{"light":"github-light","dark":"github-dark"}}
FlexImageUpload::make('illustration')
    ->imagesOnly()
    ->imageEditor()
    ->editableSvgs()
    ->confirmSvgEditing();
```

Use `editableSvgs(false)` to forbid SVG editing. The inherited default permits SVG editing without a confirmation; `confirmSvgEditing()` makes the format change explicit. The editor is a static-image workflow and does not preserve animation when exporting a crop of an animated image. For ordinary static images, browser canvas encoding determines the available output formats; circular crops and edited SVGs use PNG.

## Private disks and existing images

```php theme={"theme":{"light":"github-light","dark":"github-dark"}}
FlexImageUpload::make('photo')
    ->imagesOnly()
    ->imageEditor()
    ->disk('s3')
    ->visibility('private')
    ->directory('private-photos');
```

Stored image access is resolved through the field's disk or Spatie adapter when editing is opened. Configure valid temporary URLs and CORS for your storage so the browser can fetch the original. A thumbnail resolver changes only presentation; it does not replace the editor's original-image source. Existing images must belong to the field and be authorized for access.

## Translations and related configuration

Editor labels come from the package language files, including the `file_upload.editor` keys. Publish/override translations using [Configuration](https://flex-fields.bjanczak.com/docs/configuration.md). For translated alt text, titles and captions, configure the separate [file information editor](https://flex-fields.bjanczak.com/docs/file-upload-metadata.md); these are editorial metadata, rather than pixel adjustments.

* [Upload API reference](https://flex-fields.bjanczak.com/docs/file-upload-api.md)
* [Images, conversions and alternate sources](https://flex-fields.bjanczak.com/docs/file-upload-images-and-sources.md)
* [Avatar gallery configuration](https://flex-fields.bjanczak.com/docs/file-upload-avatar-gallery.md)
* [Save uploads to your own gallery tables](https://flex-fields.bjanczak.com/docs/file-upload-gallery-recipe.md)

## Optional AI editing

To edit images using a configured AI model, add the separate [AI image editor](https://flex-fields.bjanczak.com/docs/file-upload-ai-image-editor.md). It supports model-specific references and output settings, temporary comparisons and explicit replacement through the upload field.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.