定制 adevendorf/craft-pretzelimage 二次开发

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

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

adevendorf/craft-pretzelimage

Composer 安装命令:

composer require adevendorf/craft-pretzelimage

包简介

Generate image transforms upon image request in realtime -- load via web server directly as public files, or combine with a CDN.

README 文档

README

Pretzel Image generates image transforms at browser request time. The resulting image is stored in a public folder. Because the controller route is the same as the actual file, we let the web server serve the actual file before passing it off to the plugin to process the request.

The generated file can be deleted from the server at any time because it will just be recreated if it no longer exists.

The images are organized into a two character directory, then asset ID subdirectory. This is done to mitigate the possibility, of too many directories/files in a single folder.

The original purpose of this plugin is to place a CDN in front of the site so that these generated images would only live a short time on the actual Craft CMS server.

In practice, this plugin works well for multi-instance Craft CMS setups on high traffic sites. By utilizing an NFS server, you can reuse the same generated images between all the servers, then load balance the CMS for image generation.

Configuration

Pretzel should work out of the box, but you can customize it.

PRETZEL_PATH

By default images are stored in the @web/_imgs directory, but you can override it in your .env file with PREZTEL_PATH

PRETZEL_PATH="images"

PRETZEL_HOSTS

Pretzel will allow images to be generated by any host when in Craft CMS is in Dev Mode, otherwise it will only accept referrers from the current defined site url, or hosts you define in:

PRETZEL_HOSTS="www.somesite.com,help.somesite.com"

How to use

There are 3 arguments you pass into a url method.

  1. The Craft CMS Asset
  2. Object (or Array) of transformations
  3. (Optional) Default object of transformations that will be applied to all images
craft.pretzel.url(asset, { width: 100, height: 50 }, { position: asset.getFocalPoint() });

Twig

{% set asset = craft.assets().one() %}

{% set images = craft.pretzel.url(asset, [
    { width: 600, ratio: 1/1},
    { width: 1024, ratio: 16/9 }
], { position:asset.getFocalPoint()|default('50% 50%') }) %}

<img src="{{ images[0] }}" alt="{{ asset.title }}" />

If multiple transformation configurations are passed, an array is returned instead of a URL string.

PHP (Element API)

use adevendorf\pretzelimage\Plugin;

$asset = $entry->image->one();
$image = Plugin::$plugin->pretzelService->url($asset, [
  'width' => 600, 'height' => 360, 'position' => $asset->getFocalPoint()
]);

Image Options

width

height:

ratio

position: 50-50 (default)

mode: crop (default), fill

Requirements

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

TODO

  • Automatically remove old images from the file space based on age of the file.
  • Provide an option to never store the generated file.
  • Allow the definition of the CDN URL instead of using the Craft CMS Site URL.
  • Test GraphQL Support

adevendorf/craft-pretzelimage 适用场景与选型建议

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: mit
  • 更新时间: 2023-12-12