rachel / nova-image-cropper
A Laravel Nova field.
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Language:Vue
Requires
- php: >=7.1.0
This package is auto-updated.
Last update: 2025-04-29 01:04:21 UTC
README
This field extends Image Field adding a handy cropper to manipulate images. Can be configurable in the same way as a File field in Nova.
Demo
Install
Run this command into your nova project:
composer require rachel/nova-image-cropper
Add it to your Nova Resource:
use Rachel\NovaImageCropper\ImageCropper; ImageCropper::make('Photo'),
Update form
In order to edit the existing image saved in the model, ImageCroper uses the preview method to return a base64 encoded image. You can either use the default implementation or override it as long as you return a base64 image.
use Rachel\NovaImageCropper\ImageCropper; ImageCropper::make('Photo') ->preview(function () { if (!$this->value) return null; $url = Storage::disk($this->disk)->url($this->value); $filetype = pathinfo($url)['extension']; return 'data:image/' . $filetype . ';base64,' . base64_encode(file_get_contents($url)); });
Options
Avatar mode
You can add a rounded mask to the preview and the cropper
ImageCropper::make('Photo')->avatar()
Custom aspect ratio
Define the fixed aspect ratio of the crop box. By default, the crop box is free ratio.
- Type: Number
- Default: NaN
ImageCropper::make('Photo')->aspectRatio(16/9)
Localization
Set your translations in the corresponding xx.json file located in /resources/lang/vendor/nova
... "Edit Image": "Editar Imagen", "Cancel Crop": "Cancelar Recorte", "Change Image": "Cambiar Imagen", "Done": "Hecho", "Click here or drop the file to upload": "Click aquĆ o arrastra el archivo para comenzar la subida"