承接 visol/viresponsiveimages 相关项目开发

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

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

visol/viresponsiveimages

Composer 安装命令:

composer require visol/viresponsiveimages

包简介

Responsive images for fluid_styled_content

README 文档

README

This extensions provides a ResponsiveImageViewHelper and a SrcSetViewHelper to provide responsive images based on the srcset approach. It supports crop variants, but also defining an own ratio.

While srcset is supported in most current browsers, for background images a similar approach with a custom data-bgset attributes can be used.

Compatibility and Maintenance

This package is currently maintained for the following versions:

TYPO3 Version Package Version Branch Maintained
TYPO3 13.4.x 4.x master Yes
TYPO3 12.4.x 3.x - No
TYPO3 11.5.x 2.x - No
TYPO3 10.4.x 1.x - No
TYPO3 9.5.x 0.9.x - No

Usage in Fluid

Usage Example

This example ist showing the setup for a header image, added in the page properties in a desktop and mobile version. Sidenote: title="" to suppress the optional title attribute in the image tag.

Add {namespace viresp=Visol\Viresponsiveimages\ViewHelpers} to your Fluid template

<f:if condition="{page.files}">
    <f:if condition="{page.files.0.properties.crop}">
        <f:then>
            <div class="img-desktop hidden-xs">
            <viresp:responsiveImage
                    cropVariant="headerImageDesktop"
                    treatIdAsReference="true"
                    src="{page.files.0.uid}"
                    class="img-cropped"
                    alt="{page.files.0.properties.alternative}"
                    additionalAttributes="{data-sizes: 'auto'}"
                    title="{page.files.0.properties.title}"
            />
            </div>
            <div class="img-mobile hidden-sm hidden-md hidden-lg">
                <f:comment>
                    mobile image:
                    if set in editor 'teaserImageMobile' cropping is applied.
                    if not, the image is cropped in the given ratio from the center
                </f:comment>
                <viresp:responsiveImage
                        cropVariant="headerImageMobile"
                        treatIdAsReference="true"
                        ratio="4:2"
                        sizes="320,640"
                        src="{page.files.0.uid}"
                        class="img-autocropped"
                        alt="{page.files.0.properties.alternative}"
                        additionalAttributes="{data-sizes: 'auto'}"
                        title="{page.files.0.properties.title}"
                />
            </div>
        </f:then>
        <f:else>
            <div class="img-desktop hidden-xs">
                <f:comment>
                    no image cropping as ben seleted in the editor:
                    the image weill be cropped in the given ratio relative to the center
                    for desktop the full range of sizes will be generated
                </f:comment>
                <viresp:responsiveImage
                    treatIdAsReference="true"
                    ratio="1170:200"
                    src="{page.files.0.uid}"
                    class="img-autocropped"
                    alt="{page.files.0.properties.alternative}"
                    additionalAttributes="{data-sizes: 'auto'}"
                    title="{page.files.0.properties.title}"
            />
            </div>
            <div class="img-mobile hidden-sm hidden-md hidden-lg">
                <f:comment>
                    no image cropping as ben seleted in the editor:
                    the image weill be cropped in the given ratio relative to the center
                    for mobile only the given sizes (comma separated) will be generated
                </f:comment>
                <viresp:responsiveImage
                        treatIdAsReference="true"
                        ratio="4:2"
                        sizes="320,640"
                        src="{page.files.0.uid}"
                        class="img-autocropped"
                        alt="{page.files.0.properties.alternative}"
                        additionalAttributes="{data-sizes: 'auto'}"
                        title="{page.files.0.properties.title}"
                />
            </div>
        </f:else>
    </f:if>
</f:if>

The corresponding image editor setup in YourSitePackage/Configuration/TCA/Overrides/pages.php would look like this:

$GLOBALS['TCA']['pages']['types'][(string)\TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_DEFAULT]['columnsOverrides']['media']['config']['overrideChildTca']['columns']['crop']['config']['cropVariants'] = [
    'headerImageDesktop' => [
        'title' => 'Header Image Desktop',
        'allowedAspectRatios' => [
            '1170:200' => [
                'title' => 'Letterbox Slot 1170:200',
                'value' => 1170 / 200,
            ]
        ],
        'coverAreas' => [
            [
                'x' => 0.02,
                'y' => 0.66,
                'width' => 0.96,
                'height' => 0.34,
            ]
        ]
    ],
    'headerImageMobile' => [
        'title' => 'Header Image Mobile',
        'allowedAspectRatios' => [
            '4:2' => [
                'title' => 'Square 4:2',
                'value' => 4 / 2,
            ]
        ],
        'coverAreas' => [
            [
                'x' => 0.02,
                'y' => 0.66,
                'width' => 0.96,
                'height' => 0.34,
            ]
        ]
    ]
];

JavaScripts

If you want to support older browsers (e.g. IE) and/or use the bgset feature to create responsive background images, you need to use the lazysizes library.

JavaScript bundled with this extension

The extension uses lazysizes.js along with the plugins respimg/ls.respimg.min.js, ls.parent-fit.min.js and ls.bgset.min.js which are all included in Resources/Private and included by

page.includeJSFooterlibs {
	lazysizes1respimg = EXT:viresponsiveimages/Resources/Public/Javascripts/lazysizes/plugins/respimg/ls.respimg.min.js
	lazysizes2parentfit = EXT:viresponsiveimages/Resources/Public/Javascripts/lazysizes/plugins/parent-fit/ls.parent-fit.min.js
	lazysizes3bgset = EXT:viresponsiveimages/Resources/Public/Javascripts/lazysizes/plugins/bgset/ls.bgset.min.js
	lazysizes4core = EXT:viresponsiveimages/Resources/Public/Javascripts/lazysizes/lazysizes.min.js
}

Install using npm

The preferred way to include those libraries would be to disable the includes in your setup through the following TypoScript configuration

page.includeJSFooterlibs {
	lazysizes1respimg >
	lazysizes2parentfit >
	lazysizes3bgset >
	lazysizes9core >
}

and install lazysizes through npm/yarn in your project

npm install --save lazysizes

or add lazysizes to the dependencies section of your package.json

"dependencies": {
   ...
   "lazysizes": "^5.1.1",
   ...
}

Then choose your favourite way to build/include the sources from there. With webpack you would import the libraries in your main.js like:

import 'lazysizes/plugins/respimg/ls.respimg';
import 'lazysizes/plugins/parent-fit/ls.parent-fit';
import 'lazysizes/plugins/bgset/ls.bgset';
import 'lazysizes/lazysizes';

Credits

https://www.npmjs.com/package/lazysizes

visol digitale Dienstleistungen GmbH, www.visol.ch

visol/viresponsiveimages 适用场景与选型建议

visol/viresponsiveimages 是一款 基于 JavaScript 开发的 Composer 扩展包,目前已累计 4.64k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2020 年 01 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 visol/viresponsiveimages 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 4.64k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 5
  • Forks: 1
  • 开发语言: JavaScript

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2020-01-28