Search by

immera / filament-media-library

promatikunp

A folder-based media library and picker field for Filament v4/v5, built on Spatie Media Library.

Package info

github.com/immera/filament-media-library

pkg:composer/immera/filament-media-library

Statistics

Installs: 283

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

1.0 2026-07-28 14:09 UTC
No longer found in upstream repository

This package is auto-updated.

Last update: 2026-11-30 22:01:27 UTC


README

A folder-based media library and picker field for Filament v4 and v5, built on top of Spatie Media Library.

Features

  • A full-page media manager (folders, search, sort, upload, tagging, PDF page-count preview) registered as a Filament page.
  • A MediaPicker form field (extends ModalTableSelect) for selecting media from within any Filament form/resource.
  • Folder tree organization on top of Spatie Media Library's media table.
  • Automatic PDF thumbnail placeholder generation.
  • Upload compression for images and (optionally) PDFs.

Installation

composer require immera/filament-media-library

This package builds on Spatie Media Library and Spatie Tags, neither of which run their migrations automatically. If your app doesn't already have media and tags/taggables tables, publish and run them:

php artisan vendor:publish --provider="Spatie\MediaLibrary\MediaLibraryServiceProvider" --tag="medialibrary-migrations"
php artisan vendor:publish --provider="Spatie\Tags\TagsServiceProvider" --tag="tags-migrations"
php artisan migrate

Register the plugin on your panel:

use Immera\FilamentMediaLibrary\FilamentMediaLibraryPlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        // ...
        ->plugins([
            FilamentMediaLibraryPlugin::make(),
        ]);
}

Publish Filament's assets so this package's compiled CSS is copied into your public/ directory:

php artisan filament:assets

No Vite/Node setup is required for this — the package ships a precompiled, self-contained stylesheet and registers it with Filament directly. Re-run this command whenever you update the package. If your app's composer.json has a post-autoload-dump script calling @php artisan filament:upgrade (added by filament:install), this happens automatically on every composer update.

Optionally publish the default PDF thumbnail placeholder image to customize it:

php artisan vendor:publish --tag=filament-media-library-assets

Usage

use Immera\FilamentMediaLibrary\Forms\Components\MediaPicker;

MediaPicker::make('featured_image')
    ->showFileName()
    ->downloadable()
    ->acceptedFileTypes(['image/*']);

Upload compression

Files uploaded through the media library (full page and picker modal) are compressed before being stored. The compressed file replaces the upload; the original is not kept. A file is only replaced when the result is smaller, and if compression fails for any reason the original is stored untouched.

Type Behaviour Default
jpeg, png, webp Downscaled to max_dimension (never upscaled), EXIF orientation applied then metadata stripped, re-encoded at quality (jpeg/webp). Format and extension are kept. Opaque pngs still bigger than png_lossy_above are reduced to a png_colors palette (lossy); pngs with real transparency stay lossless. on
pdf Recompressed with Ghostscript. Needs the gs binary; silently skipped if it is not found. off
svg, gif, animated images, video, everything else Never touched. n/a

Images require the imagick PHP extension (skipped without it). If max_bytes is set and the result is still larger, quality is lowered in steps down to min_quality and then dimensions are reduced until it fits.

PDF compression downsamples embedded images and can break digitally signed PDFs, forms and accessibility tags. Text-only PDFs may not shrink at all. It runs during the upload request (bounded by timeout), so keep it off if you upload very large PDFs.

The compressor works on files already received by PHP, so upload_max_filesize, post_max_size and Spatie's max_file_size still apply. Raising them only makes sense if the server has enough memory to decode the images.

Publish the config to change the settings:

php artisan vendor:publish --tag=filament-media-library-config
// config/filament-media-library.php
'compression' => [
    'enabled' => true,              // master switch
    'images' => [
        'enabled' => true,
        'max_dimension' => 2560,    // longest side, px
        'quality' => 85,            // jpeg/webp
        'max_bytes' => 10485760,    // soft target (10MB), null to disable
        'min_quality' => 60,
        'png_lossy' => true,        // palette-reduce big opaque pngs (keeps .png)
        'png_colors' => 256,
        'png_lossy_above' => 512000, // bytes
        'strip_metadata' => true,
    ],
    'pdf' => [
        'enabled' => false,
        'binary' => 'gs',
        'preset' => '/ebook',       // /screen, /ebook, /printer, /prepress
        'timeout' => 120,           // seconds
    ],
],

Every option can also be set from .env:

MEDIA_LIBRARY_COMPRESSION=true
MEDIA_LIBRARY_COMPRESS_IMAGES=true
MEDIA_LIBRARY_IMAGE_MAX_DIMENSION=2560
MEDIA_LIBRARY_IMAGE_QUALITY=85
MEDIA_LIBRARY_IMAGE_MAX_BYTES=10485760
MEDIA_LIBRARY_IMAGE_MIN_QUALITY=60
MEDIA_LIBRARY_PNG_LOSSY=true
MEDIA_LIBRARY_PNG_COLORS=256
MEDIA_LIBRARY_PNG_LOSSY_ABOVE=512000
MEDIA_LIBRARY_COMPRESS_PDF=false
MEDIA_LIBRARY_GS_BINARY=gs
MEDIA_LIBRARY_PDF_PRESET=/ebook
MEDIA_LIBRARY_PDF_TIMEOUT=120

To use it in your own code, call app(\Immera\FilamentMediaLibrary\Support\MediaCompressor::class)->compress('public', $path).

License

MIT