Download the PHP package jegex/laravel-media without Composer
On this page you can find all versions of the php package jegex/laravel-media. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jegex/laravel-media
More information about jegex/laravel-media
Files in jegex/laravel-media
Package laravel-media
Short Description Laravel media library — upload, image conversions, responsive images, video thumbnails, ZIP export, and more
License MIT
Homepage https://github.com/jegex/laravel-media
Informations about the package laravel-media
jegex/laravel-media
Powerful media management package for Laravel applications. Handle file uploads, image conversions, responsive images, and video thumbnails with ease. Inspired by spatie/laravel-medialibrary.
Table of Contents
- Installation
- Quick Start
- Usage
- Adding Media
- Retrieving Media
- Media Properties
- Rendering Media
- Image Conversions
- Responsive Images
- Queue System
- Vapor Uploads
- ZIP Export
- Facade Usage
- Configuration
- Environment Variables
- Advanced Usage
- Testing
- Changelog
- License
Installation
Install the package via Composer:
Post-Installation Steps
Step 1: Publish Configuration & Migration
Step 2: Run Migration
Step 4: Configure Storage Disk (Optional)
In config/media.php or your .env file, set the default storage disk:
Then create the symbolic link for public disk:
Step 5: Configure Queue (Optional)
If you want image conversions to run asynchronously:
Quick Start
Add the HasMedia trait to your model:
Now you can attach media:
Usage
Adding Media via Model
Add the HasMedia trait to your model:
Now you can attach media:
Adding Media Directly (Standalone)
Since the model_type and model_id columns are nullable, you can create media without associating it to any model:
This is useful for global media libraries, CDN assets, or when you don't need to associate media with a specific model.
Retrieving Media
Media Properties
Custom Properties
Rendering Media
Image Conversions
Define conversions in your model:
Retrieve converted images:
Conversion Methods
| Method | Description |
|---|---|
width($px) |
Set width |
height($px) |
Set height |
fit(Fit $fit) |
Set fit mode (contain, cover, fill, etc.) |
format($format) |
Set output format (webp, avif, jpg, png) |
quality($quality) |
Set output quality (1-100) |
brightness($value) |
Adjust brightness (-100 to 100) |
contrast($value) |
Adjust contrast |
blur($value) |
Apply blur effect |
gamma($value) |
Adjust gamma |
flip($direction) |
Flip image (h, v) |
optimize() |
Optimize output image |
queued() |
Process conversion on queue |
nonQueued() |
Process conversion synchronously |
manipulate($name, $value) |
Add custom manipulation |
Image Generators
The package supports multiple file types out of the box:
- GenericImage — JPEG, PNG, GIF, BMP
- Webp — WebP images
- Avif — AVIF images
- Pdf — PDF files (thumbnail extraction)
- Svg — SVG files
- Video — Video files (thumbnail extraction via FFMPEG)
Image Optimizers
Optimizers are applied automatically when optimize() is called:
| Format | Optimizer |
|---|---|
| JPEG | Jpegoptim |
| PNG | Pngquant, Optipng |
| SVG | Svgo |
| GIF | Gifsicle |
| WebP | Cwebp |
| AVIF | Avifenc |
Responsive Images
Responsive images are generated automatically for image media files.
The package calculates optimal widths using FileSizeOptimizedWidthCalculator (30% smaller per variation) and generates a blurred tiny placeholder for progressive loading.
Queue System
Conversions and responsive images can be processed asynchronously.
Configuration
Per-Conversion Queue Setting
Jobs
| Job | Description |
|---|---|
PerformConversionsJob |
Processes image conversions |
GenerateResponsiveImagesJob |
Generates responsive image variations |
Vapor Uploads
For Laravel Vapor deployments, enable the upload route:
Routes
| Method | Route | Description |
|---|---|---|
| POST | /media-vapor |
Store new media from Vapor |
| POST | /media-vapor/finished/{mediaId} |
Mark media upload as finished |
| POST | /media-vapor/parameters |
Get upload parameters for S3 direct upload |
ZIP Export
Export media collections as ZIP archives for bulk downloads.
Export from Model
Export from Single Media
Filter by Conversion
The ZIP export uses maennchen/zipstream-php for memory-efficient streaming. Files are added directly to the stream without loading them entirely into memory.
Facade Usage
The package provides a LaravelMedia facade for convenient access to media operations without needing a model:
Configuration
The full configuration file (config/media.php):
Environment Variables
| Variable | Default | Description |
|---|---|---|
MEDIA_DISK |
public |
Default storage disk |
MEDIA_QUEUE |
'' |
Queue name |
QUEUE_CONNECTION |
sync |
Queue connection |
QUEUE_CONVERSIONS_BY_DEFAULT |
true |
Queue conversions by default |
QUEUE_CONVERSIONS_AFTER_DB_COMMIT |
true |
Run after database commit |
IMAGE_DRIVER |
gd |
Image processing driver |
FFMPEG_PATH |
/usr/bin/ffmpeg |
FFMPEG binary path |
FFPROBE_PATH |
/usr/bin/ffprobe |
FFProbe binary path |
FFMPEG_TIMEOUT |
900 |
FFMPEG timeout (seconds) |
FFMPEG_THREADS |
0 |
FFMPEG thread count |
MEDIA_DOWNLOADER_SSL |
true |
SSL verification for downloads |
MEDIA_TEMPORARY_URL_DEFAULT_LIFETIME |
5 |
Temporary URL lifetime (minutes) |
MEDIA_PREFIX |
'' |
Storage path prefix |
FORCE_MEDIA_LIBRARY_LAZY_LOADING |
true |
Force lazy loading |
ENABLE_MEDIA_LIBRARY_VAPOR_UPLOADS |
false |
Enable Vapor upload routes |
Advanced Usage
Custom Path Generator
Create a custom path generator:
Register it in config:
Or per-model:
Media Lifecycle Events
The MediaObserver handles:
- creating: Sets highest order number
- created: Dispatches conversion and responsive image jobs
- updating: Handles file renaming (if
moves_media_on_updateis true) - deleting: Removes all associated files from disk
Blade Component
Testing
Run with coverage:
Run a specific test:
Changelog
Please see CHANGELOG for more information on what has changed recently.
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-media with dependencies
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^11.0||^12.0||^13.0
spatie/image Version ^3.3.2
maennchen/zipstream-php Version ^3.1
spatie/temporary-directory Version ^2.2