michaeld555 / filament-croppie
Croppie Js Implementation Field for Filament forms
Package info
github.com/michaeld555/filament-croppie
Language:Blade
pkg:composer/michaeld555/filament-croppie
Requires
- php: ^8.1
- filament/forms: ^3.2 || ^4.0 || ^5.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- filament/spatie-laravel-media-library-plugin: ^3.2 || ^4.0 || ^5.0
- laravel/pint: ^1.0
- orchestra/testbench: ^8.0 || ^9.0 || ^10.0 || ^11.0
Suggests
- filament/spatie-laravel-media-library-plugin: Use the matching Filament major for the SpatieMediaLibraryCroppie field.
Provides
None
Conflicts
None
Replaces
None
README
Crop a single image in a Filament form before uploading it. Use Croppie to store a file path or SpatieMediaLibraryCroppie to attach the crop to a model’s media collection. Both fields support HEIC and HEIF input.
Compatibility
The field supports Filament Forms 3.2+, 4.x and 5.x. Composer selects Livewire and Laravel versions compatible with your Filament release. The package allows PHP 8.1 for existing Filament 3 installations. Filament 4 and 5 require PHP 8.2 or newer. All three Filament branches have been tested with PHP 8.2 and Laravel 12, and with PHP 8.5 and Laravel 13.
Installation
composer require michaeld555/filament-croppie php artisan filament:assets
Run php artisan filament:assets after upgrades as well. This publishes the bundled Croppie.js library, stylesheet, and on-demand HEIC decoder. To customize the defaults, publish the configuration file.
php artisan vendor:publish --tag="filament-croppie-config"
The interactive installer can also publish the configuration and translations.
php artisan filament-croppie:install
Configuration
The configuration file config/filament-croppie.php contains the defaults under modal-croppie. Each field can override them.
| Option | Description | Default Value |
|---|---|---|
title |
Modal title. | 'Manage Image' |
description |
Modal description. | 'Crop the image to the correct proportion' |
icon |
Modal icon (optional). | null |
size |
Modal size (e.g., sm, md, lg, xl, 2xl, 3xl, 4xl, etc.). |
4xl |
boundary-height |
Height of the crop boundary area. | 400 |
boundary-width |
Width of the crop boundary area. | 600 |
viewport-height |
Height of the visible crop area (viewport). | 200 |
viewport-width |
Width of the visible crop area (viewport). | 200 |
enable-resize |
Enables resizing of the viewport. | false |
enable-zoom |
Enables zooming on the image. | true |
show-zoomer |
Shows the zoom control. | true |
viewport-type |
Type of viewport (circle or square). |
circle |
Usage
Add the field to your form schema. This example stores the image on the public disk and saves its path in the avatar attribute.
use Michaeld555\FilamentCroppie\Components\Croppie; Croppie::make('avatar') ->label('Avatar') ->disk('public') ->directory('avatars');
Examples
Basic Usage with Custom Upload Path
Croppie::make('profile_picture') ->label('Profile Picture') ->disk('s3') ->directory('profile-images') ->viewportWidth('400') ->viewportHeight('400');
Circular Crop (Avatar) with Larger Modal
Croppie::make('user_avatar') ->avatar() ->forceCircleResult(true) ->modalSize('5xl') ->modalDescription('Please upload a square image for optimal results.');
Square Crop with Custom Viewport Size and Zoom Disabled
Croppie::make('product_image') ->viewportType('square') ->viewportHeight('250') ->viewportWidth('250') ->enableZoom(false) ->imageFormat('webp');
Croppie Component Methods
modalTitle(string | Closure | null $modalTitle): Sets the modal title.modalDescription(string | Closure | null $modalDescription): Sets the modal description.modalIcon(string | Closure | null $modalIcon): Sets the modal icon.modalSize(string | Closure | null $modalSize): Sets the modal size.customClasses(string | Closure | null $customClasses): Sets custom CSS classes for the Croppie container.enableOrientation(bool | Closure | null $enableOrientation): Enables/disables image orientation detection.enableResize(bool | Closure | null $enableResize): Enables/disables viewport resizing.enableZoom(bool | Closure | null $enableZoom): Enables/disables zoom on the image.enforceBoundary(bool | Closure | null $enforceBoundary): Sets whether the image should be forced to stay within the defined boundary.mouseWheelZoom(bool | Closure | string $mouseWheelZoom): Sets the mouse wheel zoom behavior (true,false, or'ctrl').showZoomer(bool | Closure | null $showZoomer): Sets whether the zoom control should be displayed.forceCircleResult(bool | Closure | null $forceCircleResult): Sets whether the crop result should be forced to a circle.viewportType(string | Closure | null $viewportType): Sets the viewport type ('circle'or'square').viewportHeight(string | Closure | null $viewportHeight): Sets the viewport height.viewportWidth(string | Closure | null $viewportWidth): Sets the viewport width.boundaryHeight(string | Closure | null $boundaryHeight): Sets the boundary height.boundaryWidth(string | Closure | null $boundaryWidth): Sets the boundary width.imageFormat(string | Closure | null $imageFormat): Sets the resulting image format (e.g., 'png', 'jpeg', 'webp').imageSize(string | Closure | null $imageSize): Sets the resulting image size ('viewport'or'original').imageName(string | Closure | null $imageName): Sets the cropped upload’s base name. Filament generates a unique storage name by default. WithpreserveFilenames(), the stored file uses this base name or the original image name and the actual output extension.
Upload behavior
Selecting an image opens the crop editor. Inside a Filament create or edit modal, pressing Escape closes the crop editor and keeps the form open. Canceling a replacement preserves the existing image. Confirming sends the cropped file through Filament’s temporary upload and validation flow. Saving the form persists the result.
HEIC and HEIF photos are decoded in the browser. The decoder loads when one of those files is selected. PNG is the default output format. Use imageFormat('jpeg') or imageFormat('webp') to change it. If you customize acceptedFileTypes(), include both the input types you want users to select and the output MIME type that Filament will validate.
Spatie Media Library
Install filament/spatie-laravel-media-library-plugin for your Filament major and run the Spatie Media Library migrations. On a form bound to a model that implements Spatie\MediaLibrary\HasMedia and uses InteractsWithMedia, use the collection field:
use Michaeld555\FilamentCroppie\Components\SpatieMediaLibraryCroppie; SpatieMediaLibraryCroppie::make('avatar') ->collection('portraits') ->viewportType('square');
The field saves the crop through the model’s media relationship and reloads it when the record is edited. It supports the official plugin’s collection and conversion options.
Development
Run composer install and composer test for the integration tests. To rebuild the distributed browser assets, run npm ci --include=dev and npm run build.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
License
Filament Croppie uses the MIT license. The bundled HEIC decoder uses LGPL-3.0-or-later.


