hosmelq/imgproxy
Composer 安装命令:
composer require hosmelq/imgproxy
包简介
Build imgproxy URLs in PHP with optional encryption and signing.
关键字:
README 文档
README
Build imgproxy URLs in PHP with optional encryption and signing.
Introduction
This package generates imgproxy URLs with every documented option (free and pro) and signs requests when you provide a key/salt pair. Long option names are emitted by default, and you can switch to the short aliases that imgproxy supports.
use HosmelQ\Imgproxy\Imgproxy; use HosmelQ\Imgproxy\ResizingType; $url = Imgproxy::create(baseUrl: 'https://imgproxy.example.com') ->format(extension: 'png') ->resize(type: ResizingType::Fit, width: 1200, height: 630) ->build(sourceUrl: 'https://example.com/image.jpg');
Requirements
- PHP 8.3+
- OpenSSL extension (for source encryption)
Installation & setup
Install via Composer:
composer require hosmelq/imgproxy
Basic usage
Getting started
Create a builder with your base URL and optional signing key/salt. Configure processing options fluently, then build the URL for a source image.
use HosmelQ\Imgproxy\Imgproxy; use HosmelQ\Imgproxy\ResizingType; use HosmelQ\Imgproxy\Support\Gravity; $builder = Imgproxy::create( baseUrl: 'https://imgproxy.example.com', key: 'b397f17682dea6270ac06941ca1e3f0f', salt: '68de0f586bdb701cf2458565bf5a6aec' ); $url = $builder ->format(extension: 'png') ->gravity(gravity: Gravity::smart()) ->quality(quality: 80) ->resize(type: ResizingType::Fit, width: 1200, height: 630) ->build(sourceUrl: 'https://example.com/product.jpg');
Switch to short option names if you want more compact URLs:
$shortUrl = $builder ->useShortOptions() ->build(sourceUrl: 'https://example.com/product.jpg');
Source encoding choices
Base64 is the default. You can output plain or encrypted sources when needed:
use HosmelQ\Imgproxy\Imgproxy; use HosmelQ\Imgproxy\SourceEncoding; // Plain source (no signature if key/salt are omitted) $plainUrl = Imgproxy::create(baseUrl: 'https://imgproxy.example.com') ->format(extension: 'png') ->usePlainSource() ->build(sourceUrl: 'https://example.com/product.jpg'); // Encrypted source (pro) $encryptedUrl = Imgproxy::create(baseUrl: 'https://imgproxy.example.com') ->format(extension: 'png') ->useEncryptedSource() ->withEncryptionKey(key: '1eb5b0e971ad7f45324c1bb15c947cb207c43152fa5c6c7f35c4f36e0c18e0f1') ->build(sourceUrl: 'https://example.com/private.jpg', encoding: SourceEncoding::Encrypted);
Signing and truncation
Provide both key and salt to enable signing, optionally truncate the signature to match your imgproxy config:
use HosmelQ\Imgproxy\Imgproxy; $signed = Imgproxy::create( baseUrl: 'https://imgproxy.example.com', key: 'b397f17682dea6270ac06941ca1e3f0f', salt: '68de0f586bdb701cf2458565bf5a6aec', signatureSize: 12, ) ->format(extension: 'png') ->build(sourceUrl: 'https://example.com/product.jpg');
Advanced usage
Custom IV generator for encrypted sources
Pass your own IV generator to withEncryptionKey when you need a specific IV strategy (for example, to align with another language implementation):
use HosmelQ\Imgproxy\Imgproxy; $url = Imgproxy::create(baseUrl: 'https://imgproxy.example.com') ->format(extension: 'png') ->useEncryptedSource() ->withEncryptionKey( key: '1eb5b0e971ad7f45324c1bb15c947cb207c43152fa5c6c7f35c4f36e0f199a', ivGenerator: fn (): string => random_bytes(16) ) ->build(sourceUrl: 'https://example.com/private.jpg');
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/imgproxy 适用场景与选型建议
hosmelq/imgproxy 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.71k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 11 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「encryption」 「image-processing」 「url-builder」 「imgproxy」 「signed-urls」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 hosmelq/imgproxy 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hosmelq/imgproxy 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 hosmelq/imgproxy 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Smarty plugin that adds some image related template syntax enchantments
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
Build imgproxy URLs in Laravel with optional encryption and signing.
统计信息
- 总下载量: 5.71k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 12
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-24