hosmelq/laravel-imgproxy
Composer 安装命令:
composer require hosmelq/laravel-imgproxy
包简介
Build imgproxy URLs in Laravel with optional encryption and signing.
关键字:
README 文档
README
Build imgproxy URLs in Laravel with optional encryption and signing.
Introduction
Build imgproxy URLs from Laravel with every documented option (free and pro). Grab a builder from the facade for external sources, or call the imgproxy disk macro when you want to start from storage paths.
use HosmelQ\Imgproxy\Laravel\Facades\Imgproxy; use HosmelQ\Imgproxy\ResizingType; $url = Imgproxy::builder() ->format(extension: 'png') ->resize(type: ResizingType::Fit, width: 1200, height: 630) ->build(sourceUrl: 'https://example.com/image.jpg');
Requirements
- PHP 8.3+
- Laravel 11+
- OpenSSL extension (for source encryption)
Installation & setup
Install via Composer:
composer require hosmelq/laravel-imgproxy
Publishing the config file
Optionally publish the config file:
php artisan vendor:publish --tag="imgproxy-config"
View the published config file.
<?php declare(strict_types=1); return [ /* |-------------------------------------------------------------------------- | Base URL |-------------------------------------------------------------------------- | | This URL is used when generating imgproxy links. Set it to the root of | your imgproxy instance, including scheme and host. | */ 'base_url' => env('IMGPROXY_BASE_URL'), /* |-------------------------------------------------------------------------- | Encryption Key |-------------------------------------------------------------------------- | | Hex-encoded AES key used for encrypted sources. Set this only when the | source encoding below is configured to "encrypted". | */ 'encryption_key' => env('IMGPROXY_ENCRYPTION_KEY'), /* |-------------------------------------------------------------------------- | Signing Keys |-------------------------------------------------------------------------- | | Hex-encoded key and salt used to sign imgproxy URLs. Provide both or | leave both empty. Signature size (bytes) trims the signature length | when your server expects a shorter value. | */ 'key' => env('IMGPROXY_KEY'), 'salt' => env('IMGPROXY_SALT'), 'signature_size' => env('IMGPROXY_SIGNATURE_SIZE'), /* |-------------------------------------------------------------------------- | Source Encoding |-------------------------------------------------------------------------- | | Controls how sources are encoded before signing. | | Supported encodings: "base64", "encrypted", "plain" | */ 'source_encoding' => env('IMGPROXY_SOURCE_ENCODING', 'base64'), /* |-------------------------------------------------------------------------- | Option Names |-------------------------------------------------------------------------- | | Use imgproxy's short option names instead of the long names. | */ 'use_short_options' => env('IMGPROXY_SHORT_OPTIONS', false), ];
Basic usage
Getting started
Use the builder from the facade. Chain options if needed, then build the URL.
use HosmelQ\Imgproxy\Laravel\Facades\Imgproxy; use HosmelQ\Imgproxy\ResizingType; use HosmelQ\Imgproxy\Support\Gravity; $url = Imgproxy::builder() ->format(extension: 'png') ->gravity(gravity: Gravity::smart()) ->quality(quality: 80) ->resize(type: ResizingType::Fit, width: 1200, height: 630) ->build(sourceUrl: 'https://example.com/assets/product.jpg');
Using the filesystem macro
Call the imgproxy macro on any filesystem disk path to build from storage.
use Illuminate\Support\Facades\Storage; $url = Storage::disk('public') ->imgproxy(path: 'images/headers/welcome.jpg') ->build();
The imgproxy macro starts from the disk path, applies your global imgproxy settings, and returns a ready-to-use URL.
Generating temporary URLs
Wrap your storage temporary URL before imgproxy processes it. Pass expiration and any disk-specific options. This uses the filesystem macro.
use Illuminate\Support\Facades\Storage; $url = Storage::disk('s3') ->imgproxy(path: 'private/reports/weekly.png') ->temporary(expiration: now()->addMinutes(10)) ->build();
The disk's temporary URL becomes the source, so the imgproxy link expires in 10 minutes alongside it.
Advanced usage
Custom IV generation
Provide your own IV generator for encrypted sources when you need a custom strategy (imgproxy pro).
use HosmelQ\Imgproxy\Laravel\Facades\Imgproxy; Imgproxy::buildIvUsing(fn (): string => random_bytes(16));
Use this when your security policy requires a specific IV pattern. The callback runs on every encrypted source build.
For more builder options and patterns, see the base package: hosmelq/imgproxy.
Testing
composer test
Deployments
Want a ready-to-run imgproxy instance? Use the Railway template:
Changelog
Please see CHANGELOG.md for recent changes.
Credits
License
The MIT License (MIT). Please see LICENSE.md for more information.
hosmelq/laravel-imgproxy 适用场景与选型建议
hosmelq/laravel-imgproxy 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.59k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 11 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「encryption」 「laravel」 「image-processing」 「url-builder」 「imgproxy」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 hosmelq/laravel-imgproxy 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hosmelq/laravel-imgproxy 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 hosmelq/laravel-imgproxy 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A simple PHP class to encrypt a string and decrypt an encrypted string
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Encryption with AES-256 and HMAC-SHA256
Allows installation of Laravel where the PHP Mcrypt extension is not available. Provides encryption using OpenSSL, or by disabling encryption entierly.
High-level cryptographic primitives and security utilities for Maatify systems including password hashing, reversible encryption, HKDF key derivation, and key rotation.
A library for reading KeePass 2.x databases
统计信息
- 总下载量: 5.59k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-27