bst27/laravel-image-proxy
Composer 安装命令:
composer require bst27/laravel-image-proxy
包简介
A Laravel image proxy to cache, minify and modify images very easily.
README 文档
README
A Laravel image proxy to cache, minify and manipulate images very easily.
Features
- Automatic image compression / minification
- Automatic caching of images on host and client side
- Flexible storage options (local, S3, SFTP etc.)
- Optional: image manipulation (resizing etc.)
- Optional: custom image filename in URL
- Easily extendable with custom strategies for image manipulation
Installation
composer require bst27/laravel-image-proxy
Per default spatie/image-optimizer is used to compress images. So make sure you install the required dependencies as described in their docs.
Usage
Use the global helper function proxy_image() to generate a secure image URL:
<img src="{{ proxy_image('images/example.jpg') }}" alt="Example">
This will automatically minify and cache the image and generate something like this:
<img src="http://localhost/img/1AXe...S11lg.jpg" alt="Example">
You can also define a strategy and filename for image manipulation:
<img src="{{ proxy_image('images/example.jpg', 'default', 'cat.jpg') }}" alt="A black cat">
This will use the default strategy for image manipulation, keep the given filename
and generate something like this:
<img src="http://localhost/img/1AX5...3c1KAw/cat.jpg" alt="A black cat">
Manipulation Strategies
To manipulate images, you can configure different strategies in config/image-proxy.php. The DefaultManipulator strategy uses spatie/image-optimizer to compress images.
'manipulation_strategy' => [ 'default' => [ 'class' => \Bst27\ImageProxy\Services\ImageManipulator\DefaultManipulator::class, 'params' => [], ], ],
Each strategy class must implement the ImageManipulator contract. You can add your own image manipulation strategy easily:
- Implement the contract interface
- Add your manipulator to the
manipulation_strategyarray of theimage-proxy.phpwith a unique strategy key. - Start using it by calling
proxy_image()with your strategy key.
Endpoints
Two routes are registered automatically:
-
Short URL:
/img/{token}.{ext} -
Named URL:
/img/{token}/{filename}
URLs to these routes are generated via proxy_image() and require a valid encrypted payload token.
You can customize them via the config.
Storage
Flysystem is used to offer flexible storage options. Per default
the original images are read from the local storage disk. The cached images are stored on the local storage disk, too.
You can customize the used storage disks using the plugin config or environment settings.
Configuration
Check image-proxy.php for default config. You can customize config via environment variables or publish the config file:
php artisan vendor:publish --provider="Bst27\ImageProxy\ImageProxyServiceProvider"
This will create config/image-proxy.php.
Tests
To run tests, you can execute the following command:
docker run --rm -it \ -u "$(id -u):$(id -g)" \ -v "$PWD":/var/www/html \ -w /var/www/html \ laravelsail/php84-composer:latest \ php vendor/bin/phpunit
bst27/laravel-image-proxy 适用场景与选型建议
bst27/laravel-image-proxy 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 621 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 06 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 bst27/laravel-image-proxy 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bst27/laravel-image-proxy 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 621
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-15