定制 xiidea/easy-imgproxy-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

xiidea/easy-imgproxy-bundle

Composer 安装命令:

composer require xiidea/easy-imgproxy-bundle

包简介

Symfony Bundle for generating secure, signed URLs for imgproxy service

README 文档

README

Tests codecov

A Symfony Bundle for generating secure, signed URLs for the imgproxy service.

Features

  • Clean, fluent Builder pattern API
  • HMAC-SHA256 signing with URL-safe Base64 encoding
  • Full Symfony integration with Dependency Injection
  • Comprehensive test coverage
  • PHP 8.1+ support

Installation

composer require xiidea/easy-imgproxy-bundle

Configuration

Add the bundle to your config/bundles.php:

return [
    // ...
    Xiidea\EasyImgProxyBundle\XiideaEasyImgProxyBundle::class => ['all' => true],
];

Create config/packages/xiidea_easy_img_proxy.yaml:

xiidea_easy_img_proxy:
  key: '%env(IMGPROXY_KEY)%'
  salt: '%env(IMGPROXY_SALT)%'
  base_url: '%env(IMGPROXY_BASE_URL)%'

Add to .env:

# Hex-encoded 32-byte key
IMGPROXY_KEY=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef

# Hex-encoded 16-byte salt
IMGPROXY_SALT=0123456789abcdef0123456789abcdef

# imgproxy service URL
IMGPROXY_BASE_URL=http://localhost:8080

Usage

Using the Builder Pattern

use Xiidea\EasyImgProxyBundle\Service\ImgProxyUrlGenerator;

// Inject the service
public function __construct(ImgProxyUrlGenerator $generator)
{
    $this->generator = $generator;
}

// Build a URL
$url = $this->generator->builder()
    ->withImageUrl('https://example.com/image.jpg')
    ->withWidth(200)
    ->withHeight(300)
    ->withQuality(80)
    ->withExtension('webp')
    ->build();

Using Inline Generation

$url = $this->generator->generate(
    'https://example.com/image.jpg',
    [
        'width' => 200,
        'height' => 300,
        'quality' => 80,
        'gravity' => 'center',
    ],
    'webp' // optional extension
);

Available Options

Dimension Options:

  • withWidth(int) - Image width in pixels
  • withHeight(int) - Image height in pixels
  • withResizing(string) - Resizing type: fit, fill, auto, force
  • withGravity(string) - Gravity: center, north, south, east, west, etc.
  • withQuality(int) - JPEG quality: 0-100

Format Option:

  • withExtension(string) - Output format: webp, png, jpg, gif, etc.

Custom Options:

  • withOption(string $key, mixed $value) - Add any custom processing option

Presets

The bundle supports two types of presets:

1. Custom Presets (Defined in Configuration)

Define reusable configurations in config/packages/xiidea_easy_img_proxy.yaml:

xiidea_easy_img_proxy:
  key: '%env(IMGPROXY_KEY)%'
  salt: '%env(IMGPROXY_SALT)%'
  base_url: '%env(IMGPROXY_BASE_URL)%'

  presets:
    thumbnail:
      options:
        width: 200
        height: 200
        resizing_type: fill
        gravity: center
        quality: 85
      extension: webp

    hero:
      options:
        width: 1200
        height: 400
        resizing_type: fill
        quality: 90
      extension: jpg

    product:
      options:
        width: 600
        quality: 90

Use custom presets in your code:

// Apply a single preset
$url = $this->generator->builder()
    ->withImageUrl('https://example.com/image.jpg')
    ->withPreset('thumbnail')
    ->build();

// Apply multiple presets (later ones override earlier ones)
$url = $this->generator->builder()
    ->withImageUrl('https://example.com/image.jpg')
    ->withPresets(['product', 'quality'])
    ->build();

// Override preset options with explicit values
$url = $this->generator->builder()
    ->withImageUrl('https://example.com/image.jpg')
    ->withPreset('thumbnail')
    ->withQuality(95)  // Overrides preset quality
    ->withExtension('png')  // Overrides preset extension
    ->build();

2. Server Presets (Defined in imgproxy)

Apply presets defined on the imgproxy server:

// Apply a single server preset
$url = $this->generator->builder()
    ->withImageUrl('https://example.com/image.jpg')
    ->withServerPreset('blurry')
    ->build();

// Apply server preset with parameters
$url = $this->generator->builder()
    ->withImageUrl('https://example.com/image.jpg')
    ->withServerPreset('blur:strong')
    ->build();

// Apply multiple server presets
$url = $this->generator->builder()
    ->withImageUrl('https://example.com/image.jpg')
    ->withServerPresets(['sharpen', 'quality:high'])
    ->build();

Combining Custom and Server Presets

Both preset types can be used together:

$url = $this->generator->builder()
    ->withImageUrl('https://example.com/image.jpg')
    ->withServerPreset('blur')          // imgproxy server preset
    ->withPreset('product')             // custom preset
    ->withQuality(90)                   // explicit option (highest priority)
    ->build();

Priority Order (highest to lowest):

  1. Explicitly set options (e.g., withWidth(300))
  2. Custom preset options
  3. Server presets (imgproxy-side)

URL Structure

Generated URLs follow the imgproxy format:

{BASE_URL}/{SIGNATURE}/{PROCESSING_PATH}/{IMAGE_URL}

Example:

http://localhost:8080/UtBg7s3YMkw5-gP...bQ/width/200/height/300/format/webp/https://example.com/image.jpg

Testing

Run the test suite:

vendor/bin/phpunit

Security

The bundle correctly implements imgproxy's signing specification:

  1. Processes all options into a URL path
  2. Signs the path using HMAC-SHA256 with the provided key
  3. Prepends the salt to the signature
  4. Encodes using URL-safe Base64 without padding
  5. Builds the final signed URL

License

MIT

xiidea/easy-imgproxy-bundle 适用场景与选型建议

xiidea/easy-imgproxy-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 158 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 xiidea/easy-imgproxy-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 xiidea/easy-imgproxy-bundle 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-08