sahm-org/sahm-laravel-image-optimizer
Composer 安装命令:
composer require sahm-org/sahm-laravel-image-optimizer
包简介
Professional backend image optimization for Laravel with WebP/AVIF conversion, responsive variants, and Lighthouse optimization. No database required.
关键字:
README 文档
README
Professional backend image optimization for Laravel 11 & 12. Convert images to WebP/AVIF, generate responsive variants, optimize for Lighthouse and Core Web Vitals. No database required.
✨ Features
- ✅ No Database Required - File-based storage with JSON metadata
- ✅ WebP & AVIF Support - Modern image formats
- ✅ Responsive Variants - Automatic generation of multiple sizes
- ✅ Lighthouse Optimized - Pass Core Web Vitals (LCP, FCP)
- ✅ Native PHP - Uses Imagick or GD (no external dependencies)
- ✅ Smart Processing - Automatic quality detection
- ✅ Queue Support - Background processing for large images
- ✅ Blur Placeholders - LQIP (Low Quality Image Placeholders)
- ✅ CDN Ready - Works with any CDN
- ✅ Artisan Commands - Bulk optimization & cleanup
- ✅ Presets - Predefined configs (avatar, thumbnail, hero, etc.)
- ✅ 70-80% Size Reduction - Without visible quality loss
📋 Requirements
- PHP: 8.2 or higher
- Laravel: 11.x or 12.x
- Extensions: Imagick (preferred) or GD
🚀 Installation
Install via Composer:
composer require sahm-org/sahm-laravel-image-optimizer
Publish configuration:
php artisan vendor:publish --tag=image-optimizer-config
🎯 Quick Start
Basic Usage
use SAHM\ImageOptimizer\Facades\ImageOptimizer; // Optimize uploaded image $imageData = ImageOptimizer::optimize($request->file('photo')); // Get image data $data = $imageData->toArray(); /* [ 'hash' => 'a3f7b2c1...', 'src' => '/storage/images/optimized/.../photo.webp', 'srcset' => '...photo-320w.webp 320w, ...photo-640w.webp 640w, ...', 'sizes' => '100vw', 'width' => 1920, 'height' => 1080, 'blur_placeholder' => 'data:image/webp;base64,...', 'is_lcp' => false, 'alt' => '', 'variants' => [...], ] */
With Options
$imageData = ImageOptimizer::optimize($request->file('photo'), [ 'quality' => 85, 'sizes' => [320, 640, 1024, 1920], 'is_lcp' => true, 'alt' => 'Hero image', ]);
Using Presets
// Avatar preset $avatar = ImageOptimizer::optimize($request->file('avatar'), [ 'preset' => 'avatar', ]); // Hero preset (optimized for LCP) $hero = ImageOptimizer::optimize($request->file('hero'), [ 'preset' => 'hero', ]);
Retrieve Optimized Image
// By hash (store this in your database) $hash = 'a3f7b2c1...'; $imageData = ImageOptimizer::get($hash); if ($imageData) { echo $imageData->src; echo $imageData->srcset; }
🎨 Frontend Integration
Laravel Blade
@if($imageData) <img src="{{ $imageData->src }}" srcset="{{ $imageData->srcset }}" sizes="{{ $imageData->sizes }}" width="{{ $imageData->width }}" height="{{ $imageData->height }}" loading="{{ $imageData->isLcp ? 'eager' : 'lazy' }}" fetchpriority="{{ $imageData->isLcp ? 'high' : 'auto' }}" alt="{{ $imageData->alt }}" /> @endif
Inertia/Vue
// Controller return Inertia::render('Page', [ 'hero' => ImageOptimizer::optimize($file, ['preset' => 'hero'])->toArray(), ]);
<!-- Component --> <template> <img :src="hero.src" :srcset="hero.srcset" :sizes="hero.sizes" :width="hero.width" :height="hero.height" :loading="hero.is_lcp ? 'eager' : 'lazy'" :fetchpriority="hero.is_lcp ? 'high' : 'auto'" :alt="hero.alt" /> </template>
🛠 Artisan Commands
# Check system info php artisan image-optimizer:info # Optimize directory php artisan image-optimizer:optimize storage/app/public/uploads --quality=85 # Cleanup old images php artisan image-optimizer:cleanup --days=30
📊 Performance
Typical Results:
| Metric | Before | AfterDownload table as XLSX fileDownload table as XLSX file |
|---|---|---|
| File Size | 2.5 MB | 650 KB (74% reduction) |
| Lighthouse Performance | 65 | 94 |
| LCP | 4.2s | 1.8s |
| FCP | 3.1s | 1.2s |
🏢 About SAHM
Created and maintained by SAHM.
sahm-org/sahm-laravel-image-optimizer 适用场景与选型建议
sahm-org/sahm-laravel-image-optimizer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「performance」 「image」 「gd」 「imagick」 「optimization」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sahm-org/sahm-laravel-image-optimizer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sahm-org/sahm-laravel-image-optimizer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sahm-org/sahm-laravel-image-optimizer 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
g4 application profiler package
CSS/Javascript Minificator, Compressor and Concatenator for TYPO3 - highly configurable frontend asset optimization for CSS/JS merging, minification and compression with optional body parsing, async/defer loading, inline output, data-ignore exclusions, SRI integrity validation/calculation, external
WordPress mu-plugin to remove jQuery Migrate from the list of jQuery dependencies and to allow jQuery to enqueue before </body> instead of in the <head>.
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
Stand-alone zoomify tile generator (format Zoomify) for use with OpenSeadragon, OpenLayers and various viewers.
Create link to static resources with cache-breaking segment based on md5 of the file
统计信息
- 总下载量: 12
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 32
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-12