承接 jordanbeattie/craftcms-images 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

jordanbeattie/craftcms-images

Composer 安装命令:

composer require jordanbeattie/craftcms-images

包简介

Render images in craftcms with optimized template tags

README 文档

README

Render images in your Craft templates with a single include. Pass in classes, fallbacks, transforms and more and have optimized images on your site compliant with Google Page Speed Insights.

Installation

Include the package in your project:

composer require jordanbeattie/craftcms-images

and install the plugin within the CMS.

Usage

Instead of writing out <img> tags in your project, pass variables to the render function which will optimize the image for you.

Variable Description
Field The CraftCMS field where users can upload a single image.
Transform The handle or attributes of an image transform to use. *See transforms.
Fallback A static URL/path to an image that can be used if there is an issue rendering the image or if the field is empty.
Class Any classes that should be added to the tag
Style Any items to be included in the style attributes
Alt Text for the alt attribute. If none is supplied and the field variable is passed, the alt text from the image model will be used.
Attributes Any other attributes to be added to the tag. This should be an array. * See attributes.

Transforms

Including transforms is the best way to serve images. You can pass the transform handle through to the include. The plugin will look for the transform with the handle provided and also a mobile version which should have the same handle appended with "Mobile". e.g. myTransformHandle and myTransformHandleMobile. You can also pass in the transform manually to avoid creating them in the CMS. See examples below. If you do not specify a format for your transformed image and the server supports WebP, the image will be returned as a WebP to accomodate best web practices.

Attributes

Often, when using third-party packages such as MatchHeight, you will need to add custom attributes. These can be passed in as an array.

attributes: {
    'data-mh': 'my-image'
}

Returning a URL

Only want to return a URL for the image? Use the URL function instead of render and simply pass in the image and transform and optional fallback image. See examples below

Examples

Full parameters

{{ craft.images.render(block.image, {
    transform: 'blockTransform', 
    fallback: 'https://example.com/fallback-image.png', 
    class: 'w-full h-full hidden md:block', 
    style: 'display:none',
    attributes: {
        'data-mh': 'my-block-image'
    }
}) }}
{{ craft.images.render(block.image, {
    transform: {
        width: 100, 
        height: 100, 
        mode: 'crop'
    }, 
    fallback: 'https://example.com/fallback-image.png', 
    class: 'w-full h-full hidden md:block', 
    style: 'display:none',
    attributes: {
        'data-mh': 'my-block-image'
    }
}) }}

Image without transform

{{ craft.images.render(block.image) }}

Static image

{{ craft.images.render({
    fallback: 'https://example.com/fallback-image.png'
) }}

Replacing an existing img tag

<img alt="" class="block max-w-full p-0 m-0 rounded-lg pointer-events-none select-none" src="{{ tab.image.one().url }}" />

should be replaced with

{{ craft.images.render(tab.image, {
    class: "block max-w-full p-0 m-0 rounded-lg pointer-events-none select-none"
) }}

or with a transform

{{ craft.images.render( tab.image, {
    transform: 'tabBlockImage',
    class: "block max-w-full p-0 m-0 rounded-lg pointer-events-none select-none"
} }}

Returning a URL

{{ craft.images.url(myImageField, {
    transform: {
        height: 100, 
        width: 100
    }
}) }}

Contact

Jordan Beattie
jordan@jordanbeattie.com
www.jordanbeattie.com

jordanbeattie/craftcms-images 适用场景与选型建议

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

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

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

围绕 jordanbeattie/craftcms-images 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2021-11-10