Download the PHP package melsaka/laravel-image-manager without Composer
On this page you can find all versions of the php package melsaka/laravel-image-manager. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download melsaka/laravel-image-manager
More information about melsaka/laravel-image-manager
Files in melsaka/laravel-image-manager
Package laravel-image-manager
Short Description A Laravel package for managing polymorphic images with automatic resizing and storage management
License MIT
Informations about the package laravel-image-manager
Laravel Image Manager Package
A comprehensive Laravel package for managing polymorphic images with automatic resizing, multiple formats support, and flexible storage options.
Features
- Polymorphic Image Relations: Associate images with any Eloquent model
- Automatic Image Resizing: Configure multiple sizes for different use cases
- Format Conversion: Convert images to WebP, JPEG, PNG, or keep original format
- Flexible Storage: Support for any Laravel filesystem disk
- Batch Operations: Store, update, sync, and delete multiple images
- Easy Configuration: Simple configuration for different models and image types
Installation
Install the package via Composer:
Publish the configuration file:
Publish the migration file: (optional)
Run the migration:
Configuration
The configuration file config/image-manager.php allows you to customize:
- Storage disk and base path
- Default image format and quality
- Model-specific image types and sizes
- Public/private access settings
Example Configuration
Important: Storage Link
If you're using the public disk (default), don't forget to create the storage link:
This creates a symbolic link from public/storage to storage/app/public, making your images accessible via URL.
Usage
1. Add the Trait to Your Model
If you want you can always eager load the model images like that (optional):
2. Configure Image Handling for the Model
By default, every model that uses the HasImages trait automatically supports a 'default' image type with predefined sizes. You can start using it immediately without any configuration:
Default Configuration
The default 'default' image type comes with these sizes:
3. Store Images
4. Retrieve Images
5. Delete Images
6. Advanced Operations
7. Eager Load Images
8. API Resources
In eloquent api resource you can do something like that:
Customizing Image Types (Optional)
You can customize the default configuration or add additional image types by implementing the supportedImages() method:
Configuration Structure
- Image Types (e.g.,
default,thumbnail,gallery,banner): Define different categories of images for your model - Sizes (e.g.,
small,medium,large): Define multiple size variations for each image type - Dimensions: Specify
widthandheightin pixels for each size - Resize Mode: Choose how the image should be processed
- Background (optional): For
padandcontainmodes, specify a background color
Resize Modes
The package uses Intervention Image for image processing. The following modes are supported:
| Mode | Behavior | Use Case |
|---|---|---|
cover |
Crop and resize to exact dimensions, maintaining aspect ratio | Profile pictures, thumbnails, hero images |
coverDown |
Like cover, but only shrinks (never enlarges) |
Thumbnails where you don't want to upscale small images |
scale |
Scale proportionally within dimensions, maintaining aspect ratio | Product images, galleries where full content matters |
scaleDown |
Like scale, but only shrinks (never enlarges) |
Preventing upscaling of small images |
resize |
Resize to exact dimensions (may distort if aspect ratio differs) | When exact dimensions are critical |
resizeDown |
Like resize, but only shrinks (never enlarges) |
Fixed dimensions without upscaling |
pad |
Resize to fit and add padding to reach exact dimensions | Consistent dimensions with preserved content |
contain |
Resize to fit within dimensions and center with padding | Product images on solid backgrounds |
Background Color: For pad and contain modes, you can optionally specify a background color (hex format without #):
Note:
- When using
scale,scaleDown,pad, orcontainmodes, the resulting image fits within the specified dimensions but may not match them exactly, as the aspect ratio is preserved. - An original size is always stored automatically alongside your configured sizes.
Best Practices
- Use descriptive type names that reflect the image's purpose (e.g.,
avatar,cover_photo,product_image) - Define multiple sizes to serve optimized images for different contexts (mobile, tablet, desktop)
- Choose
covermode for fixed-dimension containers where cropping is acceptable (e.g., square avatars, card thumbnails) - Choose
scalemode when preserving the entire image is important (e.g., product photos, artwork) - Use
*Downvariants to prevent upscaling of small images - Use
padorcontainfor consistent dimensions without cropping important content
Environment Variables
You can override configuration values using environment variables:
Requirements
- PHP ^8.2
- Laravel ^11.0 or ^12.0
- Intervention Image ^3.0
Credits
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-image-manager with dependencies
laravel/framework Version ^10.0|^11.0|^12.0
intervention/image Version ^3.0