wakeworks/silverstripe-responsive-images
Composer 安装命令:
composer require wakeworks/silverstripe-responsive-images
包简介
Configure and send a series of image size options to the client without loading any resources until a media query can be executed.
README 文档
README
Introduction
This module provides the ability to send a series of configured image sizes to the client without actually loading any resources until a media query can be executed.
This is particularly useful for sites that use responsive design, because it means that smaller viewports can receive images optimised for their size rather than pulling down a single image optimised for desktop. This module is highly configurable and relies on picturefill.js for the client-side magic.
Requirements
SilverStripe 4.0 or higher
For a SS 3.x compatible-version, please see branch 1.0
Installation
composer require heyday/silverstripe-responsive-images
How to use
Once you have this module installed, you’ll need to configure named sets of image sizes in your site’s yaml config (eg. mysite/_config/config.yml).
Note that there are no default image sets, but you can copy the config below to get started:
--- After: 'silverstripe-responsive-images/*' --- Heyday\ResponsiveImages\ResponsiveImageExtension: sets: ResponsiveSet1: css_classes: classname arguments: '(min-width: 1200px)': [800] '(min-width: 800px)': [400] '(min-width: 200px)': [100] ResponsiveSet2: template: Includes/MyCustomImageTemplate method: Fill arguments: '(min-width: 1000px) and (min-device-pixel-ratio: 2.0)': [1800, 1800] '(min-width: 1000px)': [900, 900] '(min-width: 800px) and (min-device-pixel-ratio: 2.0)': [1400, 1400] '(min-width: 800px)': [700, 700] '(min-width: 400px) and (min-device-pixel-ratio: 2.0)': [600, 600] '(min-width: 400px)': [300, 300] default_arguments: [1200, 1200] ResponsiveSet3: method: Pad arguments: '(min-width: 800px)': [700, 700, '666666'] '(min-width: 400px)': [300, 300, '666666'] default_arguments: [1200, 1200, '666666']
Now, run ?flush=1 to refresh the config manifest, and you will have the new methods injected into your Image class that you can use in templates.
$MyImage.ResponsiveSet1
$MyImage.ResponsiveSet2
$MyImage.ResponsiveSet3
The output of the first method (ResponsiveSet1) will look something like this, remember that the first matching media-query will be taken:
<picture> <source media="(min-width: 1200px)" srcset="/assets/Uploads/_resampled/SetWidth100-my-image.jpeg"> <source media="(min-width: 800px)" srcset="/assets/Uploads/_resampled/SetWidth400-my-image.jpeg"> <source media="(min-width: 200px)" srcset="/assets/Uploads/_resampled/SetWidth100-my-image.jpeg"> <img src="/assets/Uploads/_resampled/SetWidth640480-my-image.jpeg" alt="my-image.jpeg"> </picture>
The final output to your browser will place the correct image URL into one of the span tags and only one image will render. As the window is resized, new images are loaded into the DOM.
Other options
Each set should have a "default_arguments" property set in case the browser does not support media queries. By default, the "default_arguments" property results in an 800x600 image, but this can be overridden in the config.
Heyday\ResponsiveImages\ResponsiveImageExtension: default_arguments: [1200, 768]
You can also pass arguments for the default image at the template level.
$MyImage.MyResponsiveSet(900, 600)
The default resampling method is SetWidth, but this can be overridden in your config.
Heyday\ResponsiveImages\ResponsiveImageExtension: default_method: Fill
It can also be passed into your template function.
$MyImage.MyResponsiveSet('Fill', 800, 600)
wakeworks/silverstripe-responsive-images 适用场景与选型建议
wakeworks/silverstripe-responsive-images 是一款 基于 JavaScript 开发的 Composer 扩展包,目前已累计 21 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 05 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「image」 「responsive」 「silverstripe」 「picturefill」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 wakeworks/silverstripe-responsive-images 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 wakeworks/silverstripe-responsive-images 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 wakeworks/silverstripe-responsive-images 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
ResponsiveImages Plugin for October CMS
TYPO3 extension for sending responsive email templates
Analytics chooser extensions for site settings.
统计信息
- 总下载量: 21
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-05-16