ed.sukharev/twig-picture-extension
Composer 安装命令:
composer require ed.sukharev/twig-picture-extension
包简介
A Twig extension to generate picture tags
README 文档
README
A custom twig extension to add tags with multiple source type to aid new image types adoption (WebP now).
Installation
Add the library to your app's composer.json:
"require": { "ed.sukharev/twig-picture-extension": "~1.0", ... }
Add the extension to the Twig_Environment:
use PictureExtension\Twig\Extension\Picture; $twig = new Twig_Environment(...); $twig->addExtension(new Picture());
Usage
The extension provides a picture twig function, which generates a picture tag with a set of sources and fallback img tag:
{{ picture('/img/path/filename.png', 'My image alt text') }}
Which creates following output:
<picture> <source srcset="/img/path/filename.webp" type="image/webp"> <source srcset="/img/path/filename.png" type="image/png"> <img src="/img/path/filename.png" alt="My image alt text"> </picture>
Arguments
The picture function accepts 3 arguments:
picture($filename, $imgAlt, $imgClasses = [])
- filename: The filename of original image. Picture function substitutes the extension with appropriate when needed.
- alt: This is alternative text to be shown when image not available. Required so that you don't forget to add it.
- imgClasses: Array of strings to be added to
classattribute of fallbackimgtag.
Symfony2
Add a service manually
# app/config/config.yml services: pciture_extension.twig.picture: class: PictureExtension\Twig\Extension\Picture tags: - { name: twig.extension }
ed.sukharev/twig-picture-extension 适用场景与选型建议
ed.sukharev/twig-picture-extension 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 41 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 05 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「twig」 「images」 「pictures」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ed.sukharev/twig-picture-extension 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ed.sukharev/twig-picture-extension 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ed.sukharev/twig-picture-extension 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
A Laravel Nova field for distribute your images as array of object.
This Symfony bundle integrates PhpSpreadsheet into Symfony using Twig.
A Twig extension to insert css as inline styles with a tag
Pexels API Client for www.pexels.com
Caching and compression for Twig assets (JavaScript and CSS).
统计信息
- 总下载量: 41
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-05-10