makinacorpus/drupal-iresponsive
Composer 安装命令:
composer require makinacorpus/drupal-iresponsive
包简介
Image field formatter and theme functions for rendering responsive images using image styles
README 文档
README
This module brings theme functions and a field formatter to display responsive images. It supports two different HTML tags:
- <IMG> tag using srcsrc attribute;
- <PICTURE> tag using <SOURCE> elements.
The <IMG> tag supports the sizes attribute allowing to set a relative viewport sizes for images at the field display configuration level, allowing the browser to proceed with better image selection for download.
This modules won't allow you to provide your own image styles, it only provides two different modes:
- Image keeps the original image ratio;
- Square image.
Future plans is to support more complex image styles (maybe by merging this module own styles using a user provided one).
This ships the Picturefill 2.0 polyfill to ensure graceful downgrade for old browsers.
Installation
Just download and enable the module.
Confguration
You may want to override available sizes for images, default is:
[285, 570, 855, 1140, 1440]
In order to override it, just add in your settings.php file:
$conf['iresponsive_image_size_list'] = [200, 300, 500, 1400, ...];
Usage
For image fields
Select Responsive image as display formatter, quite straightforward ?
Displaying manually an image
Use one of ireponsive_img or iresponsive_picture theme hooks and
proceed this way with render arrays:
// Considering that $file is loaded file_managed. $build['my_image'] = [ '#theme' => 'iresponsive_picture', '#image_uri' => $file->uri, '#image_width' => $file->width, '#image_height' => $file->height, '#image_alt' => t("Some alternative text"), '#image_title' => t("Some HTML title tag"), // Note that 'w' is the default, and keeps ratio while 's' is for square. '#modifier' => 'w', // Default size must exist in iresponsive_image_size_list() function defaults // the 'iresponsive_image_size_list' variable if you overrided it. '#default_size' => $settings['default_size'], // If you set to true, this will include the original image, but without // any transformation (no square, etc...) in the image sources. '#include_full' => false, // Targetted image size in viewport percent (aka 'vh' unit in CSS). '#viewport' => 50, ];
Or if you write Drupal 6 old school code (but you should never do this):
// Considering that $file is loaded file_managed. theme(''iresponsive_picture', [ 'image_uri' => $file->uri, 'image_width' => $file->width, 'image_height' => $file->height, 'image_alt' => t("Some alternative text"), 'image_title' => t("Some HTML title tag"), // Note that 'w' is the default, and keeps ratio while 's' is for square. 'modifier' => 'w', // Default size must exist in iresponsive_image_size_list() function defaults // the 'iresponsive_image_size_list' variable if you overrided it. 'default_size' => $settings['default_size'], // If you set to true, this will include the original image, but without // any transformation (no square, etc...) in the image sources. 'include_full' => false, // Targetted image size in viewport percent (aka 'vh' unit in CSS). 'viewport' => 50, ]);
makinacorpus/drupal-iresponsive 适用场景与选型建议
makinacorpus/drupal-iresponsive 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 79 次下载、GitHub Stars 达 1, 最近一次更新时间为 2016 年 05 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 makinacorpus/drupal-iresponsive 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 makinacorpus/drupal-iresponsive 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 79
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2
- 更新时间: 2016-05-31