developerawam / wire-media
Premium Livewire media upload & image editor for Laravel 12. Upload, crop, zoom, rotate, flip, fullscreen lightbox, dark mode. Zero external JS dependencies.
Requires
- php: ^8.2
- illuminate/filesystem: ^12.0||^13.0
- illuminate/support: ^12.0||^13.0
- illuminate/validation: ^12.0 || ^13.0
- livewire/livewire: ^3.0 || ^4.0
Requires (Dev)
- intervention/image: ^4.0
- laravel/pint: ^1.0
- orchestra/testbench: ^10.0
- pestphp/pest: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
Suggests
- intervention/image: Required for the image library mode (resize, convert, optimize & thumbnails). Set WIRE_MEDIA_USE_IMAGE_LIBRARY=true after installing.
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-27 07:33:39 UTC
README
Premium Livewire media upload & image editor for Laravel 12/13.
Upload, crop, zoom, rotate, flip, fullscreen split file viewer (preview + details side-by-side) and fullscreen image editor with live info β zero external JS dependencies.
Works out of the box with Livewire v3 AND v4. Component assets (styles + scripts) are injected via Livewire's
@assetsmechanism, so they are loaded once per page, deduplicated, and never broken by Livewire's DOM morphing after an upload.
β Requirements
| Dependency | Version |
|---|---|
| PHP | ^8.2 - ^8.3 |
| Laravel | ^12.0 || ^13.0 |
| Livewire | ^3.0 or ^4.0 |
| Alpine.js | ^3.x |
| Intervention Image | ^4.0 (optional, for library & compress) |
π₯ Installation
composer require developerawam/wire-media
Ensure your layout includes Alpine.js and Livewire scripts:
<script defer src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script> @livewireStyles @livewireScripts
Large images: If you edit large photos (3-4 MB canvas
dataUrl), increase Livewire payload limit inconfig/livewire.php:'payload' => ['max_size' => 5 * 1024 * 1024, // 5MB
Publish (optional)
# Config php artisan vendor:publish --tag=wire-media-config # Views (to customise) php artisan vendor:publish --tag=wire-media-views # Language files php artisan vendor:publish --tag=wire-media-lang # JS assets to public/ php artisan vendor:publish --tag=wire-media-assets
Note: The published config (
config/wire-media.php) sets the defaults fordisk,directory,max-size-mb,max-files, accepted types and UI options. Any prop passed to<livewire:wire-media>overrides its config default; props left unset fall back to the config value.
Optional: Image Library Mode
By default WireMedia stores images as uploaded. You can optionally enable automatic image processing (resize, format conversion, optimisation & thumbnail generation) powered by Intervention Image:
composer require intervention/image
Then set the use_image_library config to true:
WIRE_MEDIA_USE_IMAGE_LIBRARY=true
| Config key | Default | Description |
|---|---|---|
WIRE_MEDIA_IMAGE_DRIVER |
gd |
gd or imagick |
WIRE_MEDIA_IMAGE_MAX_WIDTH / MAX_HEIGHT |
1920/1080 |
Scale down larger images to this bound |
WIRE_MEDIA_IMAGE_QUALITY |
85 |
Output quality (JPEG/WebP, 1β100) |
WIRE_MEDIA_IMAGE_FORMAT |
webp |
Output format: webp, jpg, png, gif |
The processor automatically:
- Resizes oversized images down (
scaleDown, never upscales) - Converts to the target format with quality compression
- Generates a WebP thumbnail variant (
-thumb, 400Γ400, used in the grid) - Applies to uploads and editor saves; thumbnails are removed together with their original file
When image-library mode is on, the image editor toolbar additionally exposes server-side Intervention transforms: grayscale, blur, and sharpen open a 0β100% strength slider with Apply / Cancel β the canvas previews the effect live, Apply bakes it into the image and Cancel reverts β plus one-click convert (WebP / JPG / PNG). Edits are re-encoded server-side so they stay optimised.
Fallback: when the flag is off, or
intervention/imageis not installed, WireMedia silently behaves like the default mode β nothing breaks.
Optional: Auto Compress
Lossless re-encode without resize, keep original format at high quality (92):
WIRE_MEDIA_AUTO_COMPRESS=true
When :auto-compress="true" (or config), upload is automatically compressed (same mime, no resize) only if smaller β prevents 200KB β 2MB inflation. Requires intervention/image. Library mode has priority when both are enabled and auto-compress is true (resize+webp).
| Prop | Config | Env |
|---|---|---|
:auto-compress="true" |
auto_compress |
WIRE_MEDIA_AUTO_COMPRESS |
:ui-auto-compress="true" |
ui_auto_compress |
WIRE_MEDIA_UI_AUTO_COMPRESS |
ui-auto-compress shows a Compress slider 0β100% in the editor toolbar (same UX as grayscale). Apply bakes via server compress transform if payload <900KB else client canvas.toDataURL(mime, quality) (with PNGβJPEG fallback at <100%). No visual filter preview β quality only affects export size.
π Basic Usage
<livewire:wire-media />
ποΈ All Props
| Prop | Type | Default | Description |
|---|---|---|---|
multiple |
bool |
false |
Allow multiple file selection |
accepted-extensions |
array |
[] |
Allowed extensions e.g. ['jpg','png','pdf'] |
accepted-mime-types |
array |
[] |
Allowed MIME types e.g. ['image/*','application/pdf'] |
accept-attribute |
string |
'' |
Raw HTML accept attribute string |
max-size-mb |
float |
2.0 |
Max file size in megabytes |
max-files |
int |
0 |
Max files when multiple (0 = unlimited) |
disk |
string |
'public' |
Laravel filesystem disk |
directory |
string |
'uploads' |
Sub-directory on disk |
show-preview |
bool |
true |
Show image thumbnails in grid |
show-list |
bool |
true |
Show uploaded file grid |
label |
string |
'' |
Label above dropzone |
help-text |
string |
'' |
Help text below component |
existing-files |
mixed |
null |
Pre-load files (array of paths, metadata, or Model) |
model-attribute |
string |
null |
Model column when existing-files is an Eloquent Model |
dark-mode |
bool |
false |
Force dark mode (also auto-detects OS preference) |
use-image-library |
bool |
false |
Enable image processing for this instance (requires Intervention) |
auto-compress |
bool |
false |
Lossless auto compress on upload (same mime, q92, no resize) |
ui-auto-compress |
bool |
false |
Show editor Compress slider 0β100% |
preview-only |
bool |
false |
Read-only: hide dropzone/edit/delete, only preview |
Auto-compress gating:
previewOnly=false+autoCompress=false+uiAutoCompress=falseβ no auto compress (ori stored)autoCompress=trueβ upload compressed (librarywebpifuseImageLibrary, else lossless)uiAutoCompress=trueonly β upload ori, compress viaEdit β slider β Apply β Save- both
trueβ upload compressed + UI available
π Features
Upload
- Drag & drop or click to browse
- Single or multiple files
- Extension, MIME type & file size validation
- Max file count enforcement
previewOnlyblocksupdatedFiles/removeFile/clearAll/openEditor
Preview-Only Mode
Read-only gallery from existing files only:
<livewire:wire-media :preview-only="true" :existing-files="['upload/photo.jpg', 'https://cdn.example.com/img.jpg']" :multiple="true" />
- Hides dropzone, edit, delete, clearAll, editor
- Still shows grid + lightbox (download + zoom, edit hidden)
existing-filessupports: Storage (uploads/gallery/x.jpg), public/ dynamic folder (upload/,custom_folder/viapublic_path()βasset()), external URL (https://..., S3https://bucket.s3.amazonaws.com/...), missing βdata:image/svg+xmlplaceholder βImage not foundβ.
Image Viewer β Fullscreen Split View
Click any card thumbnail (image, PDF or document) or the β fullscreen button (images).
The viewer opens as a fullscreen modal split into two panes:
Left pane β preview (adapts to file type):
- Image β
<img>with loading spinner (hidden for docs) - PDF β inline
<iframe>embed (#toolbar=0&navpanes=0) - Other documents β extension badge + "no preview" placeholder
Right pane β details (auto-fills on every slide):
- File name + status badge (
New/Existing/Missing) - Type (MIME + extension)
- Size (human readable + raw bytes)
- Disk
- Path (monospace)
- Uploaded date (localised)
- Status
Navigation & controls:
- Prev / Next (
ββkeyboard, buttons, swipe on mobile) - Scrollable thumbnail strip (images show thumbnails; documents show extension badges)
- Zoom (buttons, scroll wheel,
+/-/0β images only, hidden whenpreviewOnly) - Download in header
- Edit button in header (images only β opens the fullscreen editor, hidden when
previewOnly) Escto close
The details panel is a dedicated component with sticky header, scrollable list, and a responsive layout: on narrow screens (<768px) the panes stack vertically (preview on top, details below).
Image Editor β Fullscreen Split Stage
Click βοΈ (on an image card, in the viewer, or in the detail panel) to open the editor.
The editor opens as a fullscreen overlay (position: fixed, covers the viewport) with split stage: canvas left + live info right:
[hint: Scroll/Drag/Crop overlay at canvas bottom]
| Action | How |
|---|---|
| Zoom in/out | Scroll wheel or toolbar buttons |
| Pan | Drag when not in crop mode |
| Rotate | CW/CCW 90Β° buttons |
| Flip | Horizontal or vertical buttons |
| Crop | Enable β drag to select β Apply β |
| Compress | Slider 0β100% β Apply (PNGβJPEG at <100%) |
| Library | Grayscale/Blur/Sharpen slider + Convert WebP/JPG/PNG |
| Reset | Reset all transforms (undoes crops/convert/compress) |
- Close β button pinned to the top-right of the toolbar
- Cancel also available in the save bar
- Live info on the right updates instantly on
convert/compress/crop(type/size deltaβ smaller / β larger) and showsCompressed / Converted / Cropped / Edited β Save to applybadge + pulse onSave to serverwhenhasChanges. - Loading overlay
Convertingβ¦+ spinner onApplyandConvert(serverlibraryTransformDataUrlor clienttoDataURL). - Save options: Replace original (dispatches
file-removedfor old +image-processed), Keep both, or Download locally
Detail Panel (fallback, non-image)
For non-image files in the standard view, opening the card previously used an inline detail panel. With the fullscreen split viewer this is no longer needed β every file type now opens the unified fullscreen viewer instead.
Edit Mode
Pre-load existing files:
{{-- From path array (storage, public, or external) --}} <livewire:wire-media :existing-files="['uploads/photo.jpg', 'upload/public-img.png', 'https://cdn.example.com/img.jpg']" :multiple="true" /> {{-- From Eloquent model --}} <livewire:wire-media :existing-files="$user" model-attribute="avatar" /> {{-- Preview only (no upload) --}} <livewire:wire-media :preview-only="true" :existing-files="['upload/gallery.jpg']" />
Dark Mode
Auto-detects OS preference. Force with :dark-mode="true".
πΈ Usage Examples
{{-- Image gallery with editor + auto compress --}} <livewire:wire-media :multiple="true" :accepted-mime-types="['image/*']" :max-size-mb="10" :max-files="20" :auto-compress="true" :ui-auto-compress="true" label="Photo Gallery" :dark-mode="true" /> {{-- Preview only gallery (existing public/S3) --}} <livewire:wire-media :preview-only="true" :existing-files="['upload/photo.jpg', 'https://bucket.s3.amazonaws.com/photo.jpg']" :multiple="true" /> {{-- Document attachments --}} <livewire:wire-media :multiple="true" :accepted-extensions="['pdf','docx','xlsx']" :max-size-mb="25" label="Attachments" /> {{-- S3 upload --}} <livewire:wire-media disk="s3" directory="products/images" :accepted-mime-types="['image/*']" :max-size-mb="20" /> {{-- Library optimized --}} <livewire:wire-media :multiple="true" :use-image-library="true" :auto-compress="true" :ui-auto-compress="true" directory="uploads/library" />
π Browser Events
| Event | Payload | Description |
|---|---|---|
file-uploaded |
{ file } |
New file stored |
file-removed |
{ file } |
File deleted from storage (also dispatched on replace for old file) |
files-cleared |
β | All files deleted |
image-processed |
{ file, mode } |
Edited image saved to server (replace/add) |
The events are dispatched globally through the browser (not component-scoped), so they can be listened to from any Livewire component, plain JavaScript, or Alpine. On
replace, bothfile-removed(old) andimage-processed(new) are dispatched for parent sync.
π Listening from a Livewire component
Use the #[On] (or #[On('...')]) attribute to react to any of the events from another component. In Livewire v4 single-file components (SFC) this is done directly in the class:
<?php use Livewire\Attributes\On; use Livewire\Component; new class extends Component { public array $galleryPaths = []; #[On('file-uploaded')] public function onFileUploaded(array $file): void { // $file is the full metadata array (see "File Metadata Object" below) $this->remember($file['path']); } #[On('file-removed')] public function onFileRemoved(array $file): void { $this->forget($file['path']); } #[On('files-cleared')] public function onFilesCleared(): void { $this->galleryPaths = []; } #[On('image-processed')] public function onImageProcessed(array $file, string $mode): void { $this->remember($file['path']); \Log::info('Edited image saved', ['path' => $file['path'], 'mode' => $mode]); } /** Add a path to the list (avoids duplicates). */ protected function remember(string $path): void { if (! in_array($path, $this->galleryPaths, true)) { $this->galleryPaths[] = $path; } } /** Remove a path from the list. */ protected function forget(string $path): void { $this->galleryPaths = array_values(array_diff($this->galleryPaths, [$path])); } };
For class-based components (Livewire v3 / v4), the same works on a regular class:
<?php namespace App\Livewire; use Livewire\Attributes\On; use Livewire\Component; class PostForm extends Component { public array $attachments = []; #[On('file-uploaded')] public function onFileUploaded(array $file): void { $this->attachments[] = $file['path']; } #[On('file-removed')] public function onFileRemoved(array $file): void { $this->attachments = array_diff($this->attachments, [$file['path']]); } public function render() { return view('livewire.post-form'); } }
In Livewire v3 the attribute is
\Livewire\Attributes\Onas well;#[On]without arguments (parameter-less listeners) requires Livewire v3.5+ or v4+. Check the parameters each listener receives:file-uploaded/file-removedpass onearray,image-processedpasses two (array $file,string $mode).
π Listening from JavaScript / Alpine
Plain JS:
window.addEventListener("image-processed", (e) => { console.log("Saved:", e.detail.file.url); console.log("Mode:", e.detail.mode); // 'replace' | 'add' }); window.addEventListener("file-uploaded", (e) => { console.log("New file:", e.detail.file.original_name); });
Alpine ($dispatch):
<div x-data @file-uploaded.window="console.log($event.detail.file.path)"> ... </div> <script> document.addEventListener("file-uploaded", (e) => { // e.detail.file β metadata array }); </script>
π€ Dispatching the events yourself
You can also fire the same events from anywhere to reuse your listener logic (e.g. after restoring files on page load or simulating an upload):
// From JS β payload must match the expected shape window.dispatchEvent( new CustomEvent("file-uploaded", { detail: { file: { path: "uploads/example.jpg", url: "/storage/uploads/example.jpg" /* β¦ */, }, }, }), );
// From another Livewire component Livewire::dispatch('file-uploaded', [ 'file' => [ 'path' => 'uploads/example.jpg', 'url' => '/storage/uploads/example.jpg', // β¦ ], ]);
π File Metadata Object
[
'original_name' => 'photo.jpg',
'path' => 'uploads/uuid.webp',
'disk' => 'public', // or 'external' for CDN/S3 URLs
'url' => 'https://app.test/storage/uploads/uuid.webp', // or asset() / external URL
'size' => 204800,
'size_human' => '200 KB',
'mime' => 'image/webp',
'extension' => 'webp',
'is_image' => true,
'is_pdf' => false,
'is_document' => false,
'is_existing' => false,
'is_external' => false, // true for https://... URLs
'is_missing' => false, // true for placeholder
'thumbnail' => 'uploads/uuid-thumb.webp', // only in image-library mode
'thumbnail_url' => 'https://app.test/storage/uploads/uuid-thumb.webp',
'uploaded_at' => '2025-01-01T00:00:00+00:00',
]
In image-library mode, the original image is replaced by the optimised variant and
path/url/mime/extensionreflect the processed file, with athumbnailvariant generated for the grid. External URLs keep their original URL, public/ folder files useasset().
π Localisation
Ships with English (en) and Indonesian (id).
All UI labels β including the fullscreen viewer's details panel and editor's live info (Cropped/Compressed/Converted/Edited β Save to apply, Image Info, Convertingβ¦) β are translatable and are passed to the JavaScript layer (LightboxManager) via a labels object, so the panel renders fully localised strings.
π οΈ Technical Improvements (changelog highlights)
Component assets never break after uploads (@assets)
Styles and scripts are rendered through Livewire's @assets directive (instead of a plain @once block). This is the officially recommended Livewire mechanism for component assets:
- Assets are injected once into the page
<head>on the initial render. - Each asset gets a deterministic compile-time key, deduplicating across multiple component instances and repeated requests.
- Livewire's DOM morphing during uploads/re-renders no longer removes or corrupts the
<style>/<script>blocks β the CSS (and the Alpine componentsdaFileUpload/daImageEditor) survives every state update.
Fullscreen split file viewer (LightboxManager)
Renamed conceptually from a "lightbox" to a file viewer:
- Handles all file types β images (
<img>), PDFs (<iframe>), and other documents (extension badge + placeholder). - Split layout: responsive preview pane (left) + details pane (right, sticky header, scrollable).
previewOnlyhides edit/zoom for images. - Edit button and zoom bar are conditionally hidden for non-image files and
previewOnly. - Thumbnail strip renders extension badges for documents.
Fullscreen image editor v2
The image editor is now a fullscreen overlay (position: fixed; z-index; flex column) with split stage (canvas left + live info right):
- Toolbar (top) β stage (canvas flex + info 320px, stack on mobile) β save bar (bottom).
- Canvas uses
flex: 1andmax-height: 100%so it fills the available viewport space,hintoverlay at bottom insidecanvas-wrap. - Live info panel on the right shows
Name/Type/Size (β/β delta)/Disk/Pathand badgeCropped/Compressed/Converted/Edited β Save to applywith pulse onSave, updates instantly onconvert/compress/crop. - Loading overlay
Convertingβ¦onlibraryTransform/compress Apply(server<900KBelse clientcanvas.toDataURLwithPNGβJPEGfallback). - Added a dedicated Close β button in the toolbar (previously only "Cancel" in the save bar).
Preview-only & external/public support
- New prop
:preview-only="true"/WIRE_MEDIA_PREVIEW_ONLYhides dropzone/edit/delete/clearAll/editor, keeps grid + lightbox view. Guarded inupdatedFiles/removeFile/clearAll/openEditor. existing-filesnow supports dynamic public folders (public/upload,public/custom/...viapublic_path()), external URLs (https://..., S3), and missing β placeholderdata:image/svg+xmlβImage not foundβ withis_missingflag.
Auto compress & UI compress
auto_compress(lossless same-mimeq92, no resize) gated by:auto-compressβ no auto compress when both flags false;ui_auto_compressslider0β100%in editor (same UX as grayscale,Apply/Cancel,PNGβJPEGat<100%).- Server
storeFile/storeDataUrlonly keep processed if smaller (prevents200KBβ2MBinflation) andsaveToServerkeeps rawcanvasbytes for editor saves (no re-encode).
Multiple instances on one page (avoid blink)
When using several <livewire:wire-media> on the same page (e.g. gallery + preview-only + docs + library), always give each a unique wire:key β otherwise Livewire reuses wire:model="files" state between neighbours and the 3rd list will blink (appear β disappear) especially with a previewOnly in the middle:
<livewire:wire-media wire:key="gallery" directory="uploads/gallery" :multiple="true" /> <livewire:wire-media wire:key="preview" :preview-only="true" :existing-files="['upload/photo.jpg']" /> <livewire:wire-media wire:key="docs" directory="uploads/docs" :accepted-extensions="['pdf','docx']" /> <livewire:wire-media wire:key="library" directory="uploads/library" :use-image-library="true" :auto-compress="true" />
wire:key locks each component ID so updatedFiles/uploadedFiles don't get mixed during DOM morph. Clear view cache after adding: php artisan view:clear.
π§ͺ Testing
composer test # 45+ Pest tests in tests/WireMediaProductionTest.php covering: # upload/validation/previewOnly/existing (storage/public/external/placeholder/model), autoCompress/library, editor, events, helpers
π€ AI Skill for Agents (Laravel Boost & Opencode)
This package ships an AI skill for Laravel Boost & Opencode at resources/boost/skills/wire-media/SKILL.md (auto-discovered via resources/boost/skills).
After composer require developerawam/wire-media:
php artisan boost:list-skills # Found 5 skills # wire-media | developerawam/wire-media (or wire-media* | local if copied to .ai/skills)
Trigger when you mention wire-media, file upload, image compress/crop/convert, preview-only, or Livewire media handling. The skill covers all 15 props, existing-files (Storage uploads/, public upload/ dynamic, external https:///S3, missing placeholder), Image Library & Auto/UI Compress gating, Editor split stage with live info, Viewer split, and 4 browser events (file-uploaded/removed/cleared/image-processed with replace dispatches file-removed + image-processed).
For local development, the skill is also available as .agents/skills/wire-media/SKILL.md (Opencode) and .ai/skills/wire-media/SKILL.md (Boost user).
π Changelog
See CHANGELOG.md.
π License
MIT β see LICENSE.md.
developerawam Β· info@developerawam.com
