emiliolodigiani/laravel-images
Composer 安装命令:
composer require emiliolodigiani/laravel-images
包简介
Responsive image resizing with srcset generation for Laravel
README 文档
README
Responsive image resizing with srcset generation for Laravel.
Automatically resizes images to multiple WebP variants and generates <img> tags with srcset for optimal loading. Configurable image sources allow each project to define its own directories and URL structure.
Installation
composer require emiliolodigiani/laravel-images
Publish the config file:
php artisan vendor:publish --tag=images-config
Configuration
Define your image sources in config/images.php:
return [ 'quality' => 80, 'widths' => [400, 800, 1200, 1920, 2500], 'sources' => [ 'default' => [ 'originals' => public_path('images'), 'originals_url' => '/images', 'sizes' => public_path('images/sizes'), 'url' => '/images/sizes/{width}', ], // Add more sources as needed: 'blog' => [ 'originals' => storage_path('app/public/blog'), 'originals_url' => '/storage/blog', 'sizes' => storage_path('app/public/blog-sizes'), 'url' => '/storage/blog-sizes/{width}', ], ], ];
Each source defines:
- originals — absolute path to the directory with original images
- originals_url — public URL prefix for originals (used as fallback when no resized versions exist)
- sizes — absolute path where resized versions are stored (subdirectories per width)
- url — public URL pattern for srcset (
{width}is replaced with the actual value)
Usage
Blade component
<x-img src="photo.webp" alt="A photo" /> <x-img src="photo.webp" alt="A photo" sizes="(min-width: 768px) 50vw, 100vw" /> <x-img src="photo.webp" alt="A photo" source="guides" />
The component outputs an <img> tag with srcset and sizes attributes. If no resized versions exist, it falls back to the original.
HTML body helper
For rich text content with embedded <img> tags:
{!! responsive_images($model->body) !!}
This transforms all <img> tags in the HTML to responsive versions with srcset, sizes, and loading="lazy".
Resize after upload
The package does not handle file storage — your app saves files using Laravel's filesystem (Storage, Livewire storeAs(), controller store(), etc.). After saving, call ImageResizer::resize() with the absolute path to generate all resized versions.
The resize() method automatically detects which configured source the file belongs to based on its path.
use EmilioLodigiani\LaravelImages\ImageResizer; // Livewire component $this->photo->storeAs('', $filename, 'my-disk'); ImageResizer::resize(storage_path('app/public/photos/' . $filename)); // Controller $request->file('image')->store('photos', 'public'); ImageResizer::resize(storage_path('app/public/photos/' . $filename)); // Downloaded from URL (e.g. MCP tool) file_put_contents($path, Http::get($url)->body()); ImageResizer::resize($path);
Deleting images
Use ImageResizer::delete() to remove an image and all its resized versions:
ImageResizer::delete('photo.jpg', 'default');
Batch resize
Generate missing resized versions for all configured sources:
php artisan images:resize
Programmatic access
use EmilioLodigiani\LaravelImages\ImageResizer; // Get available widths for an image $widths = ImageResizer::availableWidths('photo', 'default'); // [400, 800, 1200, 1920] // Get the public URL for a specific size $url = ImageResizer::url('photo', 800, 'default'); // /images/sizes/800/photo.webp
How it works
- When an image is resized, WebP versions are generated for each configured width that is smaller than the original
- Images are scaled by their longer side (portrait images scale by height, not width)
- A PHP manifest file at
storage/framework/image-sizes.phptracks which sizes exist for fast lookup (no database queries) - The manifest is automatically updated after each resize operation and OPcache-invalidated for zero-downtime deploys
Customizing the view
Publish the Blade view to customize the <img> output:
php artisan vendor:publish --tag=images-views
The view will be at resources/views/vendor/laravel-images/components/img.blade.php.
Requirements
- PHP 8.2+
- Laravel 11 or 12
- Intervention Image 3 (GD driver)
License
MIT
emiliolodigiani/laravel-images 适用场景与选型建议
emiliolodigiani/laravel-images 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 815 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「images」 「resize」 「responsive」 「laravel」 「srcset」 「Webp」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 emiliolodigiani/laravel-images 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 emiliolodigiani/laravel-images 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 emiliolodigiani/laravel-images 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova field for distribute your images as array of object.
Pexels API Client for www.pexels.com
ResponsiveImages Plugin for October CMS
TYPO3 CMS extension to create gallery content element with preset crop ratios and pagination
TYPO3 extension for sending responsive email templates
Image cache
统计信息
- 总下载量: 815
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 33
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-22