gumlet/craft-gumlet-imagetransformer 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

gumlet/craft-gumlet-imagetransformer

Composer 安装命令:

composer require gumlet/craft-gumlet-imagetransformer

包简介

Gumlet image transformer for Craft CMS

README 文档

README

Adds Gumlet powered asset transforms to Craft CMS:

  1. Drop-in replacement for Craft CMS native image transforms and .srcset() method
  2. Add additional Gumlet parameters to image transforms
  3. Use Gumlet for CP thumbnails
  4. Allows .pdf files to be rasterized and transformed (unlike Craft CMS transforms)

The only thing you'll need to update is your filesystem Base URL to use your Gumlet domain.

Requirements

This plugin requires Craft CMS 4.0.0 or later, and PHP 8.0.2 or later.

Installation

You can install this plugin with Composer.

composer require gumlet/craft-gumlet-imagetransformer -w && php craft plugin/install gumlet-imagetransformer

Then update your filesystem Base URL to use your Gumlet domain.

Configuration

Copy config.php into Craft's config folder and rename it to gumlet-imagetransformer.php.

cp vendor/gumlet/craft-gumlet-imagetransformer/src/config.php config/gumlet-imagetransformer.php

Update the gumletDomain config setting with your Gumlet domain.

return [
    'gumletDomain' => 'your-domain.gumlet.io',
    'enabled' => true,
    'defaultQuality' => 80,
    'defaultFormat' => 'auto',
    'autoFormat' => true,
];

Usage

This plugin provides multiple ways to generate Gumlet URLs for your images:

  1. Automatic transformer (when configured as default) - Works with asset.setTransform() and asset.url
  2. Twig function - Use gumletUrl() function in templates
  3. Service method - Use craft.gumlet.buildUrl() in templates

Method 1: Using Twig Function (Recommended)

The easiest way to generate Gumlet URLs is using the gumletUrl() Twig function:

{# Basic usage with transform array #}
<img src="{{ gumletUrl(asset, { width: 300, height: 300 }) }}" alt="{{ asset.title }}" />

{# With additional Gumlet parameters #}
<img src="{{ gumletUrl(asset, { width: 300, height: 300 }, { blur: 10, brightness: 5 }) }}" alt="{{ asset.title }}" />

{# With quality and format #}
<img src="{{ gumletUrl(asset, { width: 500, height: 500, quality: 85, format: 'webp' }) }}" alt="{{ asset.title }}" />

Method 2: Using Service Method

You can also use the Gumlet service directly:

{# Basic usage #}
<img src="{{ craft.gumlet.buildUrl(asset, { width: 300, height: 300 }) }}" alt="{{ asset.title }}" />

{# With Gumlet-specific parameters as third argument #}
<img src="{{ craft.gumlet.buildUrl(asset, { width: 300, height: 300 }, { blur: 10 }) }}" alt="{{ asset.title }}" />

{# Without transform (just replaces domain) #}
<img src="{{ craft.gumlet.buildUrl(asset) }}" alt="{{ asset.title }}" />

Method 3: Using Asset Transforms and Transformation Arrays

If the Gumlet transformer is set as the default, you can use Craft's native transform methods:

{# Set the transform #}
{% do asset.setTransform({ 
    width: 300, 
    height: 300,
}) %}

{# Render the tag #}
{{ tag('img', {
  src: asset.url,
  width: asset.width,
  height: asset.height,
  srcset: asset.getSrcset(['1.5x', '2x', '3x']),
  alt: asset.title,
}) }}

Direct Transformation Array Support

You can now also pass a transformation array directly to getUrl, getWidth, and getHeight:

{% set thumb = {
  mode: 'crop',
  width: 100,
  height: 100,
  quality: 75,
  position: 'top-center'
} %}

<img
  src="{{ asset.getUrl(thumb) }}"
  width="{{ asset.getWidth(thumb) }}"
  height="{{ asset.getHeight(thumb) }}">

This works for both standard named transforms and custom arrays, and will always generate a Gumlet URL.

Note: The automatic transformer may not always be active depending on your Craft CMS configuration. Using gumletUrl() or craft.gumlet.buildUrl() is more reliable.

Adding Additional Gumlet Parameters

In addition to the standard Craft CMS transform options:

  • mode
  • width
  • height
  • quality
  • format
  • position
  • fill

You can also apply additional Gumlet parameters by passing them as the third argument:

{# Using gumletUrl() function #}
<img src="{{ gumletUrl(asset, { width: 300, height: 300 }, { blur: 20, brightness: 10, contrast: 5 }) }}" alt="{{ asset.title }}" />

{# Using service method #}
<img src="{{ craft.gumlet.buildUrl(asset, { width: 300, height: 300 }, { blur: 20, brightness: 10 }) }}" alt="{{ asset.title }}" />

Available Gumlet Parameters

Gumlet supports many transformation parameters. Some common ones include:

  • blur - Apply blur effect (0-100)
  • brightness - Adjust brightness (-100 to 100)
  • contrast - Adjust contrast (-100 to 100)
  • saturation - Adjust saturation (-100 to 100)
  • sharpen - Sharpen the image (0-100)
  • rotate - Rotate image (degrees)
  • flip - Flip image ('h' for horizontal, 'v' for vertical)
  • watermark - Add watermark
  • text - Add text overlay

For a complete list of available parameters, see the Gumlet Image Transformation API documentation.

Note: This plugin uses Gumlet's standard short parameter names (w for width, h for height, q for quality, f for format). These are the default parameter names used by Gumlet's image transformation API.

Mapping

Transform Modes

Craft CMS transform modes are mapped to Gumlet fit parameters:

  • cropcrop
  • fitclip
  • stretchscale
  • letterboxclip

Position

Craft CMS positions are mapped to Gumlet crop positions:

  • top-lefttop-left
  • top-centertop
  • top-righttop-right
  • center-leftleft
  • center-centercenter
  • center-rightright
  • bottom-leftbottom-left
  • bottom-centerbottom
  • bottom-rightbottom-right

Support

For issues, questions, or contributions, please visit the GitHub repository.

License

This plugin is licensed under the MIT License. See LICENSE for details.

Credits

Developed by Anshul Bansal

gumlet/craft-gumlet-imagetransformer 适用场景与选型建议

gumlet/craft-gumlet-imagetransformer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 84 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 11 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「image」 「plugin」 「cms」 「transform」 「Craft」 「craftcms」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 gumlet/craft-gumlet-imagetransformer 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-11-20