承接 emiliolodigiani/laravel-images 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

  1. When an image is resized, WebP versions are generated for each configured width that is smaller than the original
  2. Images are scaled by their longer side (portrait images scale by height, not width)
  3. A PHP manifest file at storage/framework/image-sizes.php tracks which sizes exist for fast lookup (no database queries)
  4. 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 我们能提供哪些服务?
定制开发 / 二次开发

基于 emiliolodigiani/laravel-images 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 815
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 33
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-22