Download the PHP package moonlight-poland/laravel-context-aware-thumbnails without Composer
On this page you can find all versions of the php package moonlight-poland/laravel-context-aware-thumbnails. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download moonlight-poland/laravel-context-aware-thumbnails
More information about moonlight-poland/laravel-context-aware-thumbnails
Files in moonlight-poland/laravel-context-aware-thumbnails
Package laravel-context-aware-thumbnails
Short Description Context-Aware on-demand thumbnail generation for Laravel with intelligent path organization, Smart Crop, AVIF/WebP support, Laravel Native Signed URLs, and variants system. Automatically organize thumbnails by user/post/album. Zero config, blazing fast! Laravel 12+ ready.
License MIT
Informations about the package laravel-context-aware-thumbnails
πΌοΈ Laravel Context-Aware Thumbnailsβ’
Intelligent On-Demand Image Thumbnails with Smart Crop & Modern Formats
Copyright Β© 2024-2026 Moonlight Poland. All rights reserved.
Contact: [email protected]
License: Commercial License - Free for personal use, paid for commercial use
Repository: https://github.com/Moonlight4000/laravel-thumbnails
Generate image thumbnails on-the-fly in Laravel with Context-Aware Thumbnailsβ’ - the only package that organizes thumbnails exactly where your content lives!
No pre-generation needed. No Redis required. Smart organization included.β’
π What Makes Us Unique?
- π― Context-Aware Organizationβ’ - Thumbnails organized by user/post/album (no other package does this!)
- βοΈ React/Vue/JavaScript Support - The ONLY Laravel thumbnail package with
sync-jscommand for frontend frameworks - π Signed URLs (Facebook-style) - Time-limited, cryptographically signed URLs to prevent hotlinking
- π€ Smart Crop with AI Energy Detection - Automatically focuses on important image areas
- π AVIF/WebP Support - Modern formats for 50%+ smaller file sizes
- π Commercial Licensing - Professional support & tamper detection included
π Table of Contents
- Why Choose This Over Other Packages?
- What Makes Context-Aware Thumbnailsβ’ Special?
- License Notice
- Features
- Installation
- Quick Start
- Configuration
- Usage
- Blade Directive
- Helper Function
- Eloquent Trait
- React / Vue / JavaScript Usage
- Signed URLs (Facebook-style Protection)
- Context-Aware Thumbnailsβ’
- Advanced Features
- Artisan Commands
- Testing
- Contributing
- License
- Credits
π Why Choose This Over Other Packages?
π Complete Feature Comparison
| Feature | Laravel Smart Thumbnailsβ’ (moonlight-poland) |
askancy/ laravel-smart-thumbnails |
lee-to/ laravel-thumbnails |
spatie/ laravel-medialibrary |
|---|---|---|---|---|
| π― UNIQUE FEATURES | ||||
| Context-Aware Organizationβ’ | β ONLY US! | β | β | β |
| Custom path templates | β
{user_id}/{post_id} |
β | β | β οΈ Limited |
| Per-user/post isolation | β Built-in | β Manual | β Manual | β οΈ Via DB |
| Commercial licensing | β $500-$15k | β MIT (free) | β MIT | β Spatie |
| πΌοΈ IMAGE PROCESSING | ||||
| AVIF format support | β v2.0+ | β | β | β |
| WebP format support | β v2.0+ | β | β | β |
| Smart Crop (AI energy) | β v2.0+ | β | β | β |
| Crop/Fit/Resize methods | β All 3 | β SmartCrop | β All 3 | β Yes |
| Multiple drivers | β GD/Imagick/Intervention | β GD/Imagick | β οΈ Intervention only | β Yes |
| Quality control | β Per size | β Per variant | β Global | β Yes |
| π‘οΈ ERROR HANDLING | ||||
| Silent/Strict modes | β v2.0+ | β | β | β οΈ Limited |
| Bulletproof fallbacks | β | β | β οΈ Basic | β |
| Never breaks app | β | β | β οΈ Can throw | β |
| β‘ GENERATION | ||||
| On-demand (lazy) | β Automatic | β Automatic | β Manual | β Manual |
| Middleware fallback | β Auto 404βgenerate | β | β | β |
| Zero config | β Works out-of-box | β οΈ Requires setup | β οΈ Setup needed | β Complex |
| π ORGANIZATION | ||||
| Subdirectory strategies | β Context-aware | β 5 strategies | β Flat | β οΈ Via DB |
| Hash-based distribution | β οΈ Manual | β Automatic | β | β |
| Date-based folders | β οΈ Manual | β Automatic | β | β |
| Handles millions of files | β Yes | β Yes | β οΈ Slow | β Yes |
| π¨ VARIANTS & PRESETS | ||||
| Multiple sizes per preset | β | β Variants | β | β |
| Responsive images | β | β | β | β |
| Named presets | β
'small', 'large' |
β | β | β |
| π§ DEVELOPER EXPERIENCE | ||||
| Blade directive | β
@thumbnail() |
β | β | β |
| Helper function | β
thumbnail() |
β | β | β |
| Eloquent trait | β
HasThumbnails |
β | β | β |
| React/Vue/JS | β ONLY US! | β | β | β |
| Auto-sync JS helper | β
sync-js |
β | β | β |
| Artisan commands | β generate, clear, sync-js | β purge, optimize | β | β Many |
| π MONITORING | ||||
| Statistics & analytics | β v2.0+ | β Full | β | β |
| Performance metrics | β v2.0+ | β | β | β οΈ |
| Disk usage tracking | β v2.0+ | β | β | β |
| π SECURITY | ||||
| File validation | β v2.0+ | β | β οΈ Basic | β |
| Size limits | β v2.0+ | β | β | β |
| Extension whitelist | β v2.0+ | β | β | β |
| Signed URLs (Facebook-style) | β v2.0.16+ | β | β | β οΈ Via S3 |
| Time-limited links | β v2.0.16+ | β | β | β |
| Hotlinking prevention | β v2.0.16+ | β | β | β οΈ Via S3 |
| Tamper detection | β Commercial only | β | β | β |
| πΎ STORAGE | ||||
| Filesystem cache | β | β | β | β |
| Redis/Memcached tags | β | β | β | β οΈ |
| Multi-disk support | β | β | β | β |
| S3/Cloud storage | β | β | β | β |
| Database storage | β | β | β | β |
| π¦ INSTALLATION | ||||
| Installs | π New | 17 | ~500 | 50,000+ |
| Stars | β New | 1 | ~50 | 5,000+ |
| Maturity | β v3.2.0 | π v2.0 | β οΈ v1.x | β v11.x |
π― Which Package Should You Choose?
Choose Laravel Context-Aware Thumbnailsβ’ (moonlight-poland) if you need:
- β Context-Aware organization (unique feature!)
- β Thumbnails organized by user/post/album automatically
- β React/Vue/JavaScript support (ONLY package with sync-js!)
- β Signed URLs (Facebook-style) - Time-limited, cryptographically signed protection
- β Auto-strategy: Context-Aware for models, Hash for paths
- β Smart Crop with energy detection (v2.0)
- β AVIF/WebP modern formats (v2.0)
- β Variants system for multiple sizes (v2.0)
- β Daily usage statistics sent to Moonlight (v2.0)
- β Blade directives and helpers for easy use
- β Automatic middleware fallback
- β Commercial support with licensing
- β Simple filesystem-based solution
π₯ What Makes Context-Aware Thumbnailsβ’ Special?
Other packages dump all thumbnails in one folder. We organize them exactly where your content lives:
Benefits:
- β Delete post β thumbnails automatically deleted with folder
- β Per-user backups β backup specific user folders
- β CDN routing β route different contexts to different CDNs
- β Filesystem performance β fewer files per directory = faster I/O
- β Security β isolate user content with directory permissions
- β Organization β find thumbnails instantly, no database queries
β οΈ License Notice
This is a COMMERCIAL package with a dual-licensing model:
- π FREE for personal/non-commercial use
- πΌ PAID for commercial use ($500-$15,000/year)
See LICENSE.md for details.
Contact: [email protected]
GitHub: https://github.com/Moonlight4000/laravel-thumbnails
β¨ Features
- π₯ Context-Aware Thumbnailsβ’ - Organize thumbnails by user/post/album/any structure (UNIQUE!)
- π On-Demand Generation - Thumbnails generated only when requested (lazy loading)
- π Signed URLs (Facebook-style) - Time-limited, cryptographically signed URLs to prevent hotlinking
- πΎ Filesystem Cache - Fast subsequent loads, no Redis/Memcached needed
- π Zero Configuration - Sensible defaults, works out of the box
- π¨ Multiple Drivers - GD (default), Imagick, or Intervention Image
- π 3 Resize Methods - Resize (proportional), Crop (exact size), Fit (with padding)
- π§ Fully Configurable - Custom sizes, quality, drivers, paths, and more
- π― Blade Directive -
@thumbnail('path/image.jpg', 'small', 'post', ['user_id' => 1]) - βοΈ React/Vue/JavaScript Helper - Full feature parity with PHP (sync-js command)
- π¦ Facade & Helpers - Multiple ways to use
- ποΈ Auto Cleanup - Delete folder = thumbnails gone
- π οΈ Artisan Commands - Generate or clear thumbnails via CLI
- β Laravel 10, 11 & 12 - Tested on PHP 8.1β8.4
π¦ Installation
Optional Dependencies (Recommended)
For best performance and advanced features, install these optional packages:
What you get with optional dependencies:
- β Smart Crop - AI-powered energy detection (requires Intervention Image)
- β AVIF format - Modern image format with 50% smaller files (requires ext-imagick)
- β Better performance - Intervention Image is faster than GD for large images
- β οΈ Without them - Package falls back to GD (works, but limited features)
License
Put your licence key in .env:
Local development on localhost / 127.0.0.1 / ::1 needs no key β in the local and
testing environments only.
How the check behaves (3.2.0+):
- A verified licence is remembered for 30 days. In between there is no network traffic at all, across processes, queue workers and restarts.
- One attempt at a time, with a 2-second timeout. If the licence server cannot be reached, thumbnails keep working on the last verified licence and the check is retried after 24 hours.
- Only a definitive rejection from the licence server replaces thumbnails with a small "licence required" placeholder.
Verify now β and schedule it daily, so the check never runs during a page request:
| Setting | Default | Meaning |
|---|---|---|
THUMBNAILS_LICENSE_CACHE_DAYS |
30 |
how long a verified licence is trusted without asking again |
THUMBNAILS_LICENSE_TIMEOUT |
2 |
seconds one verification attempt may take |
THUMBNAILS_LICENSE_GRACE_DAYS |
90 |
days past its expiry the last licence keeps working while the server is unreachable |
Contact for licensing: [email protected]
Optional: Publish Config
Make Sure Storage is Linked
For React/Vue Apps: Generate JS Helper
REQUIRED if using React, Vue, or any JavaScript framework:
This generates resources/js/utils/thumbnails.js with your config contexts.
When to run:
- β After installation
- β
After changing
config/thumbnails.php - β After adding new contexts
See React/Vue Usage section below for details.
π Quick Start
Basic Usage (Blade)
That's it! π
- First request: Generates thumbnail (~50-200ms)
- Next requests: Cached file served by Nginx (~1-5ms)
π₯ Context-Aware Thumbnailsβ’ (UNIQUE FEATURE!)
The only Laravel package that organizes thumbnails exactly where your content lives!
Why Context Matters
Traditional packages dump all thumbnails into one folder. This causes:
- β Messy filesystem (thousands of files in one directory)
- β Difficult cleanup (delete post, but thumbnails remain)
- β No per-user isolation
- β CDN routing nightmare
- β Slow backups (can't backup specific content types)
Context-Aware Thumbnailsβ’ solves this:
Configuration
Define custom contexts in config/thumbnails.php:
PHP Usage
Model Integration
Benefits
β
Perfect organization - thumbnails live with their content
β
Easy cleanup - delete post folder, thumbnails gone
β
Per-user isolation - great for multi-tenant apps
β
CDN-friendly - route /user-posts/1/* to User 1's CDN
β
Faster backups - backup specific content types
β
Better performance - fewer files per directory
π¨ React / Vue / JavaScript Usage
π UNIQUE FEATURE: We are the ONLY Laravel thumbnail package that provides seamless React/Vue/JavaScript integration with automatic context synchronization! Other packages only work with Blade.
IMPORTANT: For React/Vue apps, you need to generate a JavaScript helper that mirrors your PHP config.
Step 1: Generate JS Helper
This creates resources/js/utils/thumbnails.js with your contexts from config/thumbnails.php.
Run this command whenever you:
- Change
config/thumbnails.php - Add new contexts
- Change filename patterns
Step 2: Import in React/Vue
β YES, the import is REQUIRED! Without it, your React/Vue components won't have thumbnail URLs.
Available Functions
β Full Feature Parity with PHP
JavaScript helper supports ALL PHP features:
- β Context-Aware paths - Organized by user/post/album
- β
Resize methods -
crop,fit,resize - β
Modern formats -
webp,avif,jpg,png - β Quality control - 1-100
- β Smart Crop - AI energy detection (v2.0+)
- β On-demand generation - Middleware handles 404
Example with all options:
PHP Backend Setup for React
In your PHP accessor (e.g., UserPost.php):
React will:
- Call
getThumbnailUrl(media.path, 'small') - Build URL:
/storage/user-posts/1/12/thumbnails/img_thumb_small.jpg - Browser requests thumbnail
- 404 on first request β middleware generates thumbnail
- 200 on next requests β cached file served by Nginx
Workflow
Vue Example
π¦ Benefits
- β Automatic Cleanup - Delete post folder = all thumbnails gone
- β Per-User Isolation - Easy permissions & backups per user
- β CDN Routing - Route different contexts to different CDNs
- β Performance - Fewer files per directory = faster filesystem
- β Organization - Find any thumbnail instantly
- β Scalability - No "one folder with million files" problem
π Resize Methods
Choose how thumbnails should be generated:
1. Resize (Default - Proportional)
- β Preserves aspect ratio
- β No cropping
- β οΈ Final size may differ slightly from target
Use for: Product images, photos where full content must be visible
2. Crop (Exact Size - Center Crop)
- β Exact dimensions guaranteed
- β Fills entire thumbnail
- β οΈ May cut edges (center-focused)
Use for: Avatars, thumbnails in grids, cards
3. Fit (Preserve All - Add Padding)
- β Entire image visible
- β Exact dimensions
- β οΈ May have padding/borders
Use for: Logos, icons, images where nothing can be cut
Visual comparison:
π Usage Methods
1. Blade Directive
2. Facade
3. Helper Functions
4. Service Injection
5. JavaScript (Frontend)
βοΈ Configuration
Default Sizes
Drivers
GD (built-in, no extra dependencies)
Imagick (better quality, requires ext-imagick)
Intervention Image (most features, requires package)
Quality & Performance
π― Advanced Features
HasThumbnails Trait
Automatically delete thumbnails when model is deleted:
Artisan Commands
Manual Management
π V2.0 New Features
Smart Crop (AI Energy Detection)
Automatically detect the most important part of the image for intelligent cropping:
Usage:
When to use:
- Portrait photos (focuses on face/eyes)
- Product photos (focuses on the product)
- Landscape photos (focuses on horizon/main subject)
Modern Image Formats (AVIF/WebP)
Write thumbnails in a modern format with one setting (3.2.0+):
source(default) keeps each source's own format β upgrading changes no file name.webp/avifconvert. A transparent PNG keeps its transparency.- GIF keeps its format (converting would drop the animation), SVG is not rasterised, and anything the encoder on your server cannot write keeps the source format.
- Switching renames every thumbnail, so the old files become orphans β run
php artisan thumbnails:clearafterwards.
Never build a thumbnail name by substituting the source's extension yourself β once format is
set, photo.jpg has a thumbnail called photo_thumb_small.webp. Ask the package:
AVIF needs GD built with AVIF support (PHP 8.1+) or the Imagick driver. AVIF sources are decoded as well.
The older
formatsblock (auto_convert,priority) in the published config was never read by the package. It is kept only so existing config files do not change.
π Laravel Native Signed URLs Integration
Version 2.0.18+ uses Laravel's native URL::temporarySignedRoute() for signed URLs instead of custom Facebook-style implementation.
βοΈ Setup
Since 3.0 the package registers
/storage/{path}(route namestorage.serve) and its controller itself β skip steps 1 and 2 below. They describe the setup of 2.x. Adding your own route replaces the package's, and with it the package's checks (signature, expiry, and since 3.2.0 the refusal of..in the path). Steps 3 and 4 still apply.
1οΈβ£ Create StorageController (2.x only β not needed since 3.0)
Create app/Http/Controllers/StorageController.php:
2οΈβ£ Add Route with Signed Middleware (2.x only β the package registers it since 3.0)
Add to routes/web.php:
β οΈ IMPORTANT: Place this route BEFORE any catch-all routes!
3οΈβ£ Disable Laravel's Auto-Routes
In config/filesystems.php, set serve => false:
4οΈβ£ Remove public/storage Symlink
Laravel should route ALL /storage/* requests through the controller:
Why remove it?
- Symlink causes Apache/Nginx to serve files statically (bypassing Laravel)
- Static serving = NO middleware = NO signed URL validation
- Your images would load even with expired URLs! β
π― Enable Signed URLs
In .env:
Generated URLs:
β¨ How It Works
original()/thumbnail()helpers generate signed URL usingURL::temporarySignedRoute()- Browser requests the signed URL
- The package's
StorageFileControllervalidatesexpiresandsignature, and refuses any path with a..segment - If valid: the file is served with
Cache-Control: public, max-age=<expiration> - If invalid/expired:
403
ThumbnailFallback Middleware:
- When a thumbnail doesn't exist (404), the middleware generates it on-demand
- Returns
302 redirectto signed URL (if enabled), or serves the file directly when it was written under the very name that was requested - A 403 is never answered with a fresh URL (3.2.0+). A 403 means the signature was rejected; regenerating it would turn every expired link back into a working one
- Works perfectly with React/Vue/JavaScript!
ποΈ Stable URLs (stable_window, 3.2.0+)
By default every render stamps the current second into expires, so the same thumbnail gets a
different URL on every page view β and the browser can never reuse what it has already
downloaded. Turn on the stable window and the URL stays byte-identical for the whole window:
- The expiry is snapped to a window of
THUMBNAILS_URL_EXPIRATIONseconds, offset per file, so the site's URLs do not all rotate in the same second. - β οΈ A URL is then valid for between one and two windows. Choose
THUMBNAILS_URL_EXPIRATIONwith that in mind. - β οΈ Enabling it changes every signed URL once. Opt-in until 4.0.
π URL Expiration Times
π Security Benefits
- β Prevents hotlinking - Other sites can't steal your bandwidth
- β Time-limited access - Links expire after set time
- β No database required - Stateless validation
- β
Laravel native - Uses built-in
URL::temporarySignedRoute() - β Cryptographically secure - HMAC-SHA256 signatures
π Troubleshooting
Images still load after expiration?
- β
Check if
public/storagesymlink exists (delete it!) - β
Verify
serve => falseinconfig/filesystems.php - β
Clear cache:
php artisan optimize:clear
403 Invalid signature on valid URLs?
- β
Check if route is named
storage.serve - β
Verify
signedmiddleware is applied - β Ensure route is placed BEFORE catch-all routes
React/Vue images not loading?
- β
Backend must return
thumbnailURL (not justpath) - β Example:
Usage with Blade directive:
File size comparison:
- AVIF: ~50% smaller than JPEG (best quality per byte)
- WebP: ~30% smaller than JPEG
- JPG: Original compression
Variants System (Generate Multiple Sizes)
Generate multiple thumbnail sizes at once with preset collections:
Usage:
When to use:
- User avatars (small, medium, large)
- Gallery thumbnails (grid, lightbox, full-screen)
- Responsive images (different screen sizes)
Subdirectory Strategies (Performance at Scale)
Choose how thumbnails are organized on the filesystem:
Performance Benefits:
| Files | Without Subdirs | With Hash Prefix |
|---|---|---|
| 1,000 | β οΈ Slow | β Fast |
| 10,000 | β Very Slow | β Fast |
| 100,000 | β Unusable | β Fast |
| 1,000,000 | β Impossible | β Fast |
Why: Operating systems slow down with >1000 files per directory.
Security Validation
Protect against malicious file uploads:
Automatic validation: Package validates all images before processing.
Error Handling Modes
Control how the package behaves when errors occur:
Modes:
- silent (recommended for production): Log error, return original image
- strict (recommended for development): Throw exception
- fallback: Return placeholder image
Example:
Daily Usage Statistics (Privacy-Friendly)
Track thumbnail usage for analytics (commercial license holders only):
What's tracked:
- β Daily usage count (how many thumbnails generated today)
- β Methods used (resize, crop, fit)
- β Popular sizes (which sizes are most used)
- β PHP/Laravel versions
- β Domain (where package is installed)
What's NOT tracked:
- β Individual images (no filenames)
- β User data (no emails, IPs, personal info)
- β Image content (we never see your images)
View statistics: Commercial license holders can view stats at https://howtodraw.pl/developer/licenses
ποΈ How It Works
Architecture
File Structure
Before first request:
After thumbnail request:
πΌ Licensing
Choose Your License
| License | Price | Best For | Limits |
|---|---|---|---|
| Personal | FREE | Hobby projects, open-source | Non-commercial only |
| Small Business | $500/year | Startups, freelancers | 1-10 devs, <$500k revenue |
| Medium Business | $1,500/year | Growing companies | 11-50 devs, $500k-$10M revenue |
| Enterprise | $15,000/year | Large corporations | 50+ devs, unlimited |
Full details: LICENSE.md
Contact for commercial licensing: [email protected]
Why Commercial License?
- π οΈ Ongoing Development - New features, bug fixes, updates
- π¬ Priority Support - Fast response times
- π Comprehensive Docs - Tutorials, examples, best practices
- π Security Updates - Critical patches within 24h
- πΌ Business Continuity - SLA for Enterprise customers
π Comparison
| Feature | This Package | Traditional Solutions |
|---|---|---|
| Generation | On-demand (lazy) | Pre-generate all sizes |
| Performance | Fast (only needed) | Slow (generates unused) |
| Storage | Efficient | Wastes space |
| Setup | Zero config | Complex setup |
| Cache | Filesystem | Often needs Redis |
| Dependencies | ext-gd (built-in) | Various |
π Examples
Gallery with Thumbnails
Responsive Images
React Component
π€ Contributing
This is a commercial package. We welcome:
- π Bug reports (GitHub Issues)
- π‘ Feature suggestions (GitHub Issues)
- π Documentation improvements (PRs welcome)
Contact: [email protected]
π License
Commercial License with free personal tier.
See LICENSE.md for full terms.
π Credits
Inspired by:
Built with β€οΈ by Moonlight Poland Team
π Support
GitHub Issues: https://github.com/Moonlight4000/laravel-thumbnails/issues
Email: [email protected]
β If this package helped you, please star it on GitHub!
All versions of laravel-context-aware-thumbnails with dependencies
illuminate/support Version ^10.0|^11.0|^12.0
illuminate/http Version ^10.0|^11.0|^12.0
illuminate/filesystem Version ^10.0|^11.0|^12.0
ext-gd Version *