Installation:
composer require supernova3339/magickit
php artisan ui magickit
npm install && npm run dev
php artisan magickit:install if the package provides a dedicated installer command (verify via php artisan).MAGICKIT_ENABLED=true is set in .env to activate the package.First Use Case:
Magickit facade to process images on-the-fly:
use Supernova3339\Magickit\Facades\Magickit;
$path = Magickit::upload('path/to/image.jpg')
->resize(800, 600)
->watermark('watermark.png')
->save('public/uploads/processed.jpg');
MagickitMiddleware for automatic processing of uploaded files via app/Http/Kernel.php:
'web' => [
\Supernova3339\Magickit\Http\Middleware\MagickitMiddleware::class,
// ...
],
Where to Look First:
config/magickit.php for default settings (e.g., storage paths, allowed formats, watermarks).Supernova3339\Magickit\MagickitServiceProvider for booting events and bindings.Supernova3339\Magickit\Facades\Magickit for chainable methods (e.g., resize(), compress(), applyFilters()).File Processing Pipeline:
Magickit::from('input.jpg')
->resize(1200, null, 'crop') // Auto-height, crop if needed
->sharpen(10)
->applyFilters(['grayscale', 'sepia'])
->save('output.jpg');
$files = ['file1.jpg', 'file2.png'];
foreach ($files as $file) {
Magickit::from($file)->resize(400, 400)->save("thumbs/{$file}");
}
Middleware Integration:
// In a controller
public function store(Request $request) {
$request->validate(['image' => 'required|image']);
$path = $request->file('image')->store('uploads');
// Processed path is available in $request->magickit_path
}
app/Http/Kernel.php to exclude routes (e.g., API endpoints):
'api' => [
// Exclude MagickitMiddleware for API routes
],
Storage Integration:
use Storage;
$url = Magickit::from(Storage::path('raw/image.jpg'))
->resize(800, 600)
->saveAs('processed', 'public')
->getUrl();
Event Listeners:
// In EventServiceProvider
protected $listen = [
\Supernova3339\Magickit\Events\ImageProcessed::class => [
\App\Listeners\UpdateProductGallery::class,
],
];
use Supernova3339\Magickit\Rules\MagickitRule;
$request->validate([
'image' => ['required', 'image', new MagickitRule(['resize' => [1024, 768]])],
]);
dispatch(new ProcessImageJob($request->file('image'), 'thumbs'));
@magickit('image.jpg', ['resize' => [200, 200], 'watermark' => true])
Imagick Extension:
Class 'Imagick' not found or failed to apply font: 'dejavu'.imagick extension is installed and enabled:
pecl install imagick
sudo nano /etc/php/{version}/cli/php.ini # Add `extension=imagick.so`
sudo nano /etc/php/{version}/fpm/php.ini # For FPM
sudo systemctl restart php{version}-fpm
gd library (slower) by setting MAGICKIT_DRIVER=gd in .env.File Permissions:
Permission denied when saving files.chmod -R 775 storage/app/public
chown -R www-data:www-data storage/app/public # Adjust user as needed
Memory Limits:
Out of memory for large images..env:
MAGICKIT_MEMORY_LIMIT=512M
->compress(80) to reduce file size before processing.Watermark Paths:
watermarks.path in config/magickit.php points to the correct directory and files exist.Middleware Conflicts:
Call to undefined method when using magickit_path in requests.MagickitMiddleware is registered after ConvertEmptyStringsToNullMiddleware in Kernel.php.Log Processing:
Enable debug mode in .env:
MAGICKIT_DEBUG=true
Check storage/logs/laravel.log for detailed processing steps.
Test Locally:
Use php artisan magickit:test (if available) or manually test with:
Magickit::from('test.jpg')->debug()->resize(100, 100)->save('debug.jpg');
.env:
MAGICKIT_DEFAULT_WIDTH=1200
MAGICKIT_DEFAULT_QUALITY=85
MAGICKIT_ALLOWED_FORMATS=jpg,png,gif,webp
config(['magickit.key' => value]) to modify settings at runtime.Custom Filters: Add new filters by publishing the config:
php artisan vendor:publish --provider="Supernova3339\Magickit\MagickitServiceProvider" --tag="config"
Extend config/magickit.php:
'filters' => [
'custom' => [
'command' => 'modulate 100,100,100', // Darken image
'description' => 'Apply custom dark effect',
],
],
Use in code:
Magickit::from('image.jpg')->applyFilters(['custom'])->save('output.jpg');
Events:
Listen for ImageProcessed events to extend functionality:
// In a listener
public function handle(ImageProcessed $event) {
// Example: Log processed files or update analytics
Log::info('Processed ' . $event->path);
}
Service Provider Binding: Bind custom classes to the container for advanced use:
$this->app->bind('magickit.custom', function () {
return new CustomMagickitProcessor();
});
How can I help you explore Laravel packages today?