4.1 KiB
4.1 KiB
Laravel Image Cropper Installation Summary
Package Installed
- Package:
takeone/cropperfrom https://git.innovator.bh/ghassan/laravel-image-cropper - Version: dev-main
- Installation Date: January 26, 2026
Changes Made
1. composer.json
- Added VCS repository for the package
- Installed
takeone/cropper:@dev
2. resources/views/layouts/app.blade.php
- Added
@stack('modals')before closing</body>tag - This allows the cropper modal to be injected into the page
3. resources/views/family/profile-edit.blade.php
- Replaced the old
<x-image-upload-modal>component with<x-takeone-cropper> - Configured cropper with:
- ID:
profile_picture - Width: 300px
- Height: 400px (portrait rectangle - 3:4 ratio)
- Shape:
square(rectangle viewport) - Folder:
images/profiles - Filename:
profile_{user_id} - Upload URL: Custom route
profile.upload-picture
- ID:
- Added image display logic to show current profile picture or placeholder
4. app/Http/Controllers/FamilyController.php
- Updated
uploadProfilePicture()method to handle base64 image data from cropper - Method now:
- Accepts base64 image data instead of file upload
- Decodes and saves the cropped image
- Updates user's
profile_picturefield in database - Returns JSON response with success status and image path
5. resources/views/vendor/takeone/components/widget.blade.php
- Published and customized the package's widget component
- Added support for custom
uploadUrlparameter - Added page reload after successful upload to display new image
- Improved error handling with detailed error messages
6. Storage
- Ran
php artisan storage:linkto link public storage
How It Works
- User clicks "Change Photo" button on profile edit page
- Modal popup appears with file selector
- User selects an image file
- Cropme.js library loads the image in a cropping interface
- User can:
- Zoom in/out using slider
- Rotate image using slider
- Pan/move image within the viewport
- Cropping viewport is set to 300x400px (portrait rectangle)
- User clicks "Crop & Save Image"
- Image is cropped to base64 format
- AJAX POST request sent to
/profile/upload-picture - FamilyController processes the base64 image:
- Decodes base64 data
- Saves to
storage/app/public/images/profiles/profile_{user_id}.{ext} - Deletes old profile picture if exists
- Updates user's
profile_picturefield
- Page reloads to display the new profile picture
File Locations
- Uploaded Images:
storage/app/public/images/profiles/ - Public Access:
public/storage/images/profiles/(via symlink) - Database Field:
users.profile_picture
Portrait Rectangle Configuration
The cropper is configured for portrait orientation:
- Aspect Ratio: 3:4 (300px width × 400px height)
- Shape:
square(rectangle viewport, not circular) - Viewport: Displays as a rectangle overlay on the image
Testing Checklist
- Package installed successfully
- Storage linked
- Modal stack added to layout
- Cropper component integrated
- Custom upload route configured
- Controller method updated
- Test image upload
- Verify cropped image saves correctly
- Confirm image displays after upload
- Test portrait rectangle cropping
- Verify old images are deleted
Next Steps
- Navigate to http://localhost:8000/profile/edit
- Click "Change Photo" button
- Select an image
- Crop in portrait rectangle shape
- Save and verify the image appears correctly
Troubleshooting
If the cropper doesn't appear:
- Check browser console for JavaScript errors
- Verify
@stack('modals')is in layout - Ensure jQuery is loaded before the cropper script
If upload fails:
- Check
storage/app/public/images/profiles/directory exists - Verify storage is linked:
php artisan storage:link - Check file permissions on storage directory
- Review Laravel logs in
storage/logs/
Package Documentation
For more details, see:
- Package README:
vendor/takeone/cropper/README.md - Package Example:
vendor/takeone/cropper/EXAMPLE.md