Download the PHP package mainul12501/drag-drop-crop-image-upload without Composer
On this page you can find all versions of the php package mainul12501/drag-drop-crop-image-upload. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mainul12501/drag-drop-crop-image-upload
More information about mainul12501/drag-drop-crop-image-upload
Files in mainul12501/drag-drop-crop-image-upload
Package drag-drop-crop-image-upload
Short Description Laravel drag, drop, and crop image upload widget.
License MIT
Informations about the package drag-drop-crop-image-upload
Drag Drop Crop Image Upload
A Laravel package that provides an elegant drag-and-drop image upload widget with built-in cropping functionality. Perfect for profile pictures, avatars, and any image upload that requires user-controlled cropping.
Features
- Drag & drop image upload
- Interactive image cropping with Cropper.js
- Image rotation (90° left/right)
- Configurable aspect ratio, dimensions, and quality
- Base64 to file conversion with automatic format detection
- Bootstrap modal integration support
- Customizable labels and UI text
- Auto-cleanup of old images on re-upload
Requirements
| Requirement | Version |
|---|---|
| PHP | 8.1 - 8.5 |
| Laravel | 11.x, 12.x |
Installation
Via Composer (Packagist)
Publish the assets and configuration:
Local Development
Add to your main app's composer.json:
Then run:
Quick Start
1. Render the Widget in Your Blade View
2. Handle the Upload in Your Controller
Usage
Basic Usage
With Custom Options
Inside Bootstrap Modal
Custom Labels
API Reference
DragDropCrop::generateUpload(string $inputName, array $options = [])
Renders the drag-drop-crop widget.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$inputName |
string | Name attribute for the hidden input containing cropped base64 data |
$options |
array | Configuration options (see below) |
Options:
| Option | Type | Default | Description |
|---|---|---|---|
id |
string | auto-generated | Unique widget identifier |
file_input_name |
string | {inputName}_file |
Name for the file input element |
aspect_ratio |
float | 1 |
Width/height ratio (1 = square, 16/9 = widescreen) |
crop_width |
int | 300 |
Output image width in pixels |
crop_height |
int | 300 |
Output image height in pixels |
max_size_mb |
int | 5 |
Maximum allowed file size in MB |
quality |
float | 0.8 |
JPEG compression quality (0.1 - 1.0) |
modal_id |
string | null |
Bootstrap modal ID for auto-reset on close |
labels |
array | [] |
Custom UI text labels |
Returns: Illuminate\Support\HtmlString
DragDropCrop::uploadFromBase64(?string $base64String, ?string $directory, ?string $namePrefix, ?string $existingPath)
Converts base64 image data to a file and saves it.
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
$base64String |
string|null | - | Base64-encoded image data from the widget |
$directory |
string|null | config value | Upload directory relative to public/ |
$namePrefix |
string|null | null |
Prefix for the generated filename |
$existingPath |
string|null | null |
Path to existing image (will be deleted) |
Returns: string|null - Relative path to the uploaded file, or $existingPath if no new upload
Example with all parameters:
Generated filename format: {prefix}_{timestamp}_{random}.{ext}
Example: user_123_1704067200_a1b2c3d4e5.jpg
Configuration
After publishing, edit config/drag-drop-crop.php:
Complete Example
Blade View (create-profile.blade.php)
Controller (ProfileController.php)
Display the Image
Supported Image Formats
| Format | Extension | MIME Type |
|---|---|---|
| JPEG | .jpg | image/jpeg |
| PNG | .png | image/png |
| GIF | .gif | image/gif |
| WebP | .webp | image/webp |
User Interaction Flow
- User drags an image onto the widget (or clicks to browse)
- Selected image appears in the cropping interface
- User adjusts the crop area (drag, resize, rotate)
- User clicks "Crop Image" to confirm
- Cropped preview is shown with option to change
- On form submit, base64 data is sent to the server
- Server converts base64 to file and returns the path
License
MIT License. See LICENSE for details.
Credits
- Cropper.js - Image cropping library
- Built for Laravel 11 & 12
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.