### Installation and Configuration Source: https://context7.com/danihidayatx/image-optimizer/llms.txt Instructions for installing the Image Optimizer package via Composer and publishing optional configuration files. Includes commands for installation, publishing config, and publishing stubs. Also mentions server requirements like GD Library and optional Imagick support. ```bash # Install the package composer require danihidayatx/image-optimizer # Optional: Publish configuration file php artisan vendor:publish --tag=image-optimizer-config # Optional: Publish stubs for customization php artisan vendor:publish --tag=image-optimizer-stubs ``` ```php // config/image-optimizer.php return [ // Configuration options (currently empty, reserved for future use) ]; // Ensure GD Library is installed on your server // Check with: php -m | grep -i gd // For Imagick support (optional, provides better quality): // sudo apt-get install php-imagick ``` -------------------------------- ### Install Image Optimizer Package Source: https://github.com/danihidayatx/image-optimizer/blob/main/README.md Install the image optimizer package using Composer. This command ensures compatibility with Filament v3.x & v4.x, and Laravel 10, 11 & 12. ```bash composer require danihidayatx/image-optimizer ``` -------------------------------- ### Combine Optimization and Resizing using SpatieMediaLibraryFileUpload Source: https://github.com/danihidayatx/image-optimizer/blob/main/README.md Combine image optimization (e.g., to WebP) and resizing (by percentage or max dimensions) using Filament's SpatieMediaLibraryFileUpload component. This offers advanced image processing before saving with Spatie's Media Library. ```php use Filament\Forms\Components\SpatieMediaLibraryFileUpload; SpatieMediaLibraryFileUpload::make('attachment') ->image() ->optimize('webp') ->maxImageWidth(1024) ->maxImageHeight(768) ->resize(50), ``` -------------------------------- ### Combine Optimization and Resizing using FileUpload Source: https://github.com/danihidayatx/image-optimizer/blob/main/README.md Combine image optimization (e.g., to WebP) and resizing (by percentage or max dimensions) using Filament's FileUpload component for comprehensive image preparation before upload. ```php use Filament\Forms\Components\FileUpload; FileUpload::make('attachment') ->image() ->optimize('webp') ->maxImageWidth(1024) ->maxImageHeight(768) ->resize(50), ``` -------------------------------- ### Optimize Image to WebP using SpatieMediaLibraryFileUpload Source: https://github.com/danihidayatx/image-optimizer/blob/main/README.md Optimize an uploaded image to WebP format using Filament's SpatieMediaLibraryFileUpload component. This integrates with Spatie's Media Library for optimized storage. ```php use Filament\Forms\Components\SpatieMediaLibraryFileUpload; SpatieMediaLibraryFileUpload::make('attachment') ->image() ->optimize('webp'), ``` -------------------------------- ### Optimize and Resize Multiple Images using SpatieMediaLibraryFileUpload Source: https://github.com/danihidayatx/image-optimizer/blob/main/README.md Apply optimization and resizing to multiple uploaded images simultaneously using Filament's SpatieMediaLibraryFileUpload component. This allows for batch image processing before saving with Spatie's Media Library. ```php use Filament\Forms\Components\SpatieMediaLibraryFileUpload; SpatieMediaLibraryFileUpload::make('attachment') ->image() ->multiple() ->optimize('jpg') ->resize(50), ``` -------------------------------- ### Optimize Image to WebP using FileUpload Source: https://github.com/danihidayatx/image-optimizer/blob/main/README.md Optimize an uploaded image to WebP format using Filament's FileUpload component. The original file is replaced with the converted version. ```php use Filament\Forms\Components\FileUpload; FileUpload::make('attachment') ->image() ->optimize('webp'), ``` -------------------------------- ### Resize Image by Percentage using SpatieMediaLibraryFileUpload Source: https://github.com/danihidayatx/image-optimizer/blob/main/README.md Resize an uploaded image by a specified percentage using Filament's SpatieMediaLibraryFileUpload component. This method maintains the image's aspect ratio and integrates with Spatie's Media Library. ```php use Filament\Forms\Components\SpatieMediaLibraryFileUpload; SpatieMediaLibraryFileUpload::make('attachment') ->image() ->resize(50), ``` -------------------------------- ### Resize Image by Percentage using FileUpload Source: https://github.com/danihidayatx/image-optimizer/blob/main/README.md Resize an uploaded image by a specified percentage using Filament's FileUpload component. This method maintains the image's aspect ratio. ```php use Filament\Forms\Components\FileUpload; FileUpload::make('attachment') ->image() ->resize(50), ``` -------------------------------- ### Multiple Image Uploads with Filament FileUpload Source: https://context7.com/danihidayatx/image-optimizer/llms.txt Enables batch uploads for multiple images using Filament's FileUpload component. Each image can be optimized with the same settings by chaining the `multiple()` method. Supports various optimization options like format conversion, resizing, and dimension constraints. ```php use Filament\Forms\Components\FileUpload; // Upload and optimize multiple images at once FileUpload::make('gallery_images') ->image() ->multiple() ->optimize('jpg') ->resize(50) ->directory('galleries'); // Product gallery with multiple optimized images FileUpload::make('product_photos') ->image() ->multiple() ->maxItems(10) ->optimize('webp') ->maxImageWidth(800) ->maxImageHeight(800) ->directory('products'); // Spatie Media Library multiple uploads use Filament\Forms\Components\SpatieMediaLibraryFileUpload; SpatieMediaLibraryFileUpload::make('photos') ->collection('photos') ->image() ->multiple() ->optimize('webp') ->resize(50); ``` -------------------------------- ### Optimize and Resize Multiple Images using FileUpload Source: https://github.com/danihidayatx/image-optimizer/blob/main/README.md Apply optimization and resizing to multiple uploaded images simultaneously using Filament's FileUpload component. All selected images will be processed with the same settings. ```php use Filament\Forms\Components\FileUpload; FileUpload::make('attachment') ->image() ->multiple() ->optimize('jpg') ->resize(50), ``` -------------------------------- ### Optimize Image Format with Filament FileUpload Source: https://context7.com/danihidayatx/image-optimizer/llms.txt Converts uploaded images to a specified format (e.g., webp, jpg) before storage. Optionally, a quality level (0-100) can be set for formats like JPEG. This method is available for both native `FileUpload` and `SpatieMediaLibraryFileUpload` components. ```php use Filament\Forms\Components\FileUpload; // Convert uploaded images to WebP format FileUpload::make('avatar') ->image() ->optimize('webp'); // Convert to JPEG with custom quality (0-100) FileUpload::make('photo') ->image() ->optimize('jpg', 80); ``` ```php use Filament\Forms\Components\SpatieMediaLibraryFileUpload; // Works identically with Spatie Media Library SpatieMediaLibraryFileUpload::make('featured_image') ->collection('images') ->image() ->optimize('webp'); ``` -------------------------------- ### Set Maximum Image Dimensions using FileUpload Source: https://github.com/danihidayatx/image-optimizer/blob/main/README.md Set maximum width and height constraints for an uploaded image using Filament's FileUpload component. The image will be resized to fit these dimensions while maintaining its aspect ratio. ```php use Filament\Forms\Components\FileUpload; FileUpload::make('attachment') ->image() ->maxImageWidth(1024) ->maxImageHeight(768), ``` -------------------------------- ### Combine Filament Image Optimization Methods Source: https://context7.com/danihidayatx/image-optimizer/llms.txt Chains multiple optimization methods together for comprehensive image processing, including format conversion, dimension constraints, and resizing. These methods can be applied in any order to `FileUpload` and `SpatieMediaLibraryFileUpload` components. ```php use Filament\Forms\Components\FileUpload; // Full optimization: convert to WebP, constrain dimensions, and reduce size FileUpload::make('attachment') ->image() ->optimize('webp') ->maxImageWidth(1024) ->maxImageHeight(768) ->resize(50); // Blog post featured image with comprehensive optimization FileUpload::make('featured_image') ->image() ->disk('s3') ->directory('blog/featured') ->optimize('webp') ->maxImageWidth(1200) ->maxImageHeight(630) ->resize(75); ``` ```php use Filament\Forms\Components\SpatieMediaLibraryFileUpload; // Spatie Media Library with full optimization chain SpatieMediaLibraryFileUpload::make('gallery') ->collection('gallery') ->image() ->optimize('webp') ->maxImageWidth(1920) ->maxImageHeight(1080) ->resize(50); ``` -------------------------------- ### Resize Image Dimensions by Percentage with Filament FileUpload Source: https://context7.com/danihidayatx/image-optimizer/llms.txt Reduces the dimensions of uploaded images by a specified percentage, maintaining the aspect ratio. This is useful for limiting file sizes of high-resolution uploads. Applicable to `FileUpload` and `SpatieMediaLibraryFileUpload`. ```php use Filament\Forms\Components\FileUpload; // Reduce image size by 50% (e.g., 1280x720 becomes 640x360) FileUpload::make('gallery_image') ->image() ->resize(50); // Reduce by 25% for moderate compression FileUpload::make('thumbnail') ->image() ->resize(25); ``` ```php use Filament\Forms\Components\SpatieMediaLibraryFileUpload; // Combined with Spatie Media Library SpatieMediaLibraryFileUpload::make('product_image') ->collection('products') ->image() ->resize(50); ``` -------------------------------- ### Direct Image Processing with ImageProcessor Class Source: https://context7.com/danihidayatx/image-optimizer/llms.txt Allows programmatic image optimization outside of Filament forms using the `ImageProcessor` class. It automatically detects and uses Intervention Image v2 or v3. Supports processing from file paths or binary content and saving the processed image. ```php use DaniHidayatX\ImageOptimizer\ImageProcessor; // Process an image file with all optimization options $optimizedContent = ImageProcessor::process('/path/to/image.jpg', [ 'format' => 'webp', // Target format: webp, jpg, jpeg, png, gif, bmp 'resize' => 50, // Reduce by percentage (0-100) 'max_width' => 1024, // Maximum width in pixels 'max_height' => 768, // Maximum height in pixels 'quality' => 80, // Quality for JPEG/WebP (0-100) ]); // Save the processed image file_put_contents('/path/to/optimized.webp', $optimizedContent); // Process from binary content $imageContent = file_get_contents('/path/to/upload.png'); $webpContent = ImageProcessor::process($imageContent, [ 'format' => 'webp', 'max_width' => 800, ]); // Store using Laravel Storage use Illuminate\Support\Facades\Storage; Storage::disk('public')->put('images/optimized.webp', $webpContent); ``` -------------------------------- ### Set Maximum Image Width Constraint with Filament FileUpload Source: https://context7.com/danihidayatx/image-optimizer/llms.txt Constrains the uploaded image to a maximum width in pixels. If the image exceeds this width, it will be scaled down proportionally. Images smaller than the specified width are unaffected. Works with `FileUpload` and `SpatieMediaLibraryFileUpload`. ```php use Filament\Forms\Components\FileUpload; // Limit width to 1024 pixels maximum FileUpload::make('banner') ->image() ->maxImageWidth(1024); // Practical use case: profile photos with reasonable dimensions FileUpload::make('profile_photo') ->image() ->maxImageWidth(500) ->directory('profiles'); ``` -------------------------------- ### Set Maximum Image Height Constraint with Filament FileUpload Source: https://context7.com/danihidayatx/image-optimizer/llms.txt Constrains the uploaded image to a maximum height in pixels, scaling down images that exceed the limit while preserving aspect ratio. Similar to `maxImageWidth`, this applies to both `FileUpload` and `SpatieMediaLibraryFileUpload`. ```php use Filament\Forms\Components\FileUpload; // Limit height to 768 pixels maximum FileUpload::make('hero_image') ->image() ->maxImageHeight(768); // Portrait-oriented constraint for user uploads FileUpload::make('document_scan') ->image() ->maxImageHeight(1200); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.