承接 madj2k/t3-media-utils 相关项目开发

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

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

madj2k/t3-media-utils

Composer 安装命令:

composer require madj2k/t3-media-utils

包简介

TYPO3 extension providing fully configurable responsive images, media ViewHelpers and reusable partials, with support for picture tags, srcset/sizes and lazy loading.

README 文档

README

This extension provides

  • fully configurable responsive images for TYPO3
  • some helpful ViewHelpers and includable partials for the usage with media-files.

Features

  • Supports <picture>, srcset, and sizes
  • Configurable breakpoints
  • Native and JavaScript lazy loading
  • Backend configuration via settings.definitions.yaml
  • Usage of processingInstructionsBatch in TYPO3 v14 (thanks to Ayke Halder for the improvement hint)
  • Includes a media-partial for usage in own extensions
  • Includes a configuration for responsive images with Bootstrap (picture-tag only)
  • Some helpful ViewHelpers for usage with media-files
  • Configuration is backwards-compatible with EXT:sms_responsive_images
  • Fixes performance issue with upsizing of images of EXT:sms_responsive_images

Installation

Just install the extension and include the desired configuration (e.g. with or without Bootstrap) set to your site-config.

name: your/site-package
label: 'Site Package (Default)'
dependencies:
  - madj2k/media-utils-bootstrap

Ensure that you add "webp" as allowed image extension in your settings.php

$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'] = 'gif,jpg,jpeg,tif,tiff,bmp,pcx,tga,png,pdf,ai,svg,webp';

How to use

Usage with EXT:content-blocks (friendsoftypo3/content-blocks)

The extension automatically includes the configuration for responsive images to EXT:content-blocks. This way all your custom content elements have the according settings automaticllay available.

If you configure default-settings for your custom content elements, you can also include default-settings for your media files. Just follow this structure for your TypoScript-configuration:

tt_content.VENDOR_your_element {
    settings {
    	[...]
        media {
            image {
                dimensions {
                    maxWidth = 650
                }
            }
            video {
                dimensions {
                    width = 1370
                    height= 771
                }
                additionalConfig {
                    playsinline = 1 // needed for Safari on Mobile
                    autoplay = 1
                    mute = 1
                    loop = 0
                    modestbranding = 1
                }
            }
		}
    }
}

Here you also have the ability to override the default settings, e.g. if you want to use different cropVariants for each breakpoint or no native lazy-loading:

tt_content.VENDOR_your_element {
    settings {

        [...]

        txMediaUtils.responsiveImages {

            loading = eager
            breakpoints {
                0 {
                    cropVariant = default
                }
                1 {
                    cropVariant = tablet
                }
                2 {
                    cropVariant = mobile
                }
            }
        }

    	[...]
    }
}

Then call the media-partial in your content-element like this:

<f:render partial="Utils/Media" arguments="{file: image, maxWidth: 1000, settings: settings}" />

If you e.g. set a explicit maxWidth this value will be used, otherwise the default value from your TypoScript-configuration will be used. The defined configuration for responsive images is applied automatically.

There may be the case that you have multiple styles of one custom content element which require different default-settings for your media. This can be handeled by extending your TypoScript-configuration by an additional sub-key to switch between the settings. Example:

tt_content.VENDOR_your_element {
    settings {
    	[...]
        media {

            small {
                image {
                    dimensions {
                        maxWidth = 650
                    }
                }
                video {
                    dimensions {
                        width = 1370
                        height= 771
                    }
                    additionalConfig {
                        autoplay = 1
                        mute = 1
                        loop = 0
                        modestbranding = 1
                    }
                }
            }

            big {
                image {
                    dimensions {
                        maxWidth = 650
                    }
                }
                video {
                    dimensions {
                        width = 1370
                        height= 771
                    }
                    additionalConfig {
                        autoplay = 1
                        mute = 1
                        loop = 0
                        modestbranding = 1
                    }
                }
            }
		}
    }
}

Now you can call the media-partial in your content-element with the according key for the desired setting. The following call would load the default-settings for the sub-key "small":

<f:render partial="Utils/Media" arguments="{file: image, maxWidth: 1000, settings: settings, settingsVariant: 'small'}" />

Usage with EXT:mask (deprecated)

The extension automatically includes the configuration for responsive images to EXT:mask. This way all your custom content elements have the according settings automaticllay available.

This actually works exactly as described above for EXT:content-blocks (friendsoftypo3/content-blocks).

Usage in TypoScript-based FluidTemplates

The usage does not differ much from the usage with EXT:content-blocks (friendsoftypo3/content-blocks). You simply have to include the corresponding settings and the partial-path into your TypoScript. Here you also have the ability to override the default settings, e.g. if you want to use different cropVariants for each breakpoint.

lib.siteDefault {

    fluidTemplates {

        stage = FLUIDTEMPLATE
        stage {

            file = EXT:site_default/Resources/Private/FluidTemplates/Templates/Stage.html
            partialRootPaths.0 = EXT:site_default/Resources/Private/FluidTemplates/Partials/Stage/
            partialRootPaths.1 = EXT:site_default/Resources/Private/Mask/Frontend/Partials/
            partialRootPaths.1712245685 = {$plugin.tx_mediautils.view.partialRootPath}

            dataProcessing {
                10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
                10 {
                    references {
                        table = pages
                        data = levelfield: -1, media, slide
                    }
                    as = media
                }
            }

            variables {
                pageTitle = TEXT
                pageTitle.data = page:title
            }

            settings.txMediaUtils.responsiveImages < lib.txMediaUtils.responsiveImages
            settings.txMediaUtils.responsiveImages {

                loading = eager
                breakpoints {
                    0 {
                        cropVariant = default
                    }
                    1 {
                        cropVariant = tablet
                    }
                    2 {
                        cropVariant = mobile
                    }
                }
            }
        }
    }
}

Usage for images in your own extension

There are basically two ways:

Use the partial of this extension and override only the values you need to override (recommended)

  1. Extend the partialPaths accordingly:
tx_myextension {
    view {
        partialRootPaths {
            1712245685 = {$plugin.tx_mediautils.view.partialRootPath}
        }
    }
}
  1. Merge the global settings into your extension settings:
tx_myextension.settings.txMediaUtils.responsiveImages < lib.txMediaUtils.responsiveImages
  1. Use the partial accordingly and add additional settings if you want (see above)
<f:render partial="Utils/Media" arguments="{file: image, width: 1000, settings: settings}" />

Use the normal ViewHelper and insert the values of the TypoScript-lib into each parameters (not really convenient - but works)

<html xmlns:sms="http://typo3.org/ns/Sitegeist/SmsResponsiveImages/ViewHelpers" data-namespace-typo3-fluid="true">
<sms:media
	class="image-embed-item{f:if(condition: settings.txMediaUtils.class, then: ' {lib.txMediaUtils.responsiveImages.class}')}"
	file="{file}"
	width="{dimensions.width}"
	height="{dimensions.height}"
	alt="{file.alternative}"
	title="{file.title}"
	srcset="{lib.txMediaUtils.responsiveImages.srcset}"
	lazyload="{lib.txMediaUtils.responsiveImages.lazyload}"
	placeholderSize="{lib.txMediaUtils.responsiveImages.placeholder.size}"
	placeholderInline="{lib.txMediaUtils.responsiveImages.placeholder.inline}"
	sizes="{lib.txMediaUtils.responsiveImages.sizes}"
	breakpoints="{lib.txMediaUtils.responsiveImages.breakpoints}"
	ignoreFileExtensions="{lib.txMediaUtils.responsiveImages.ignoreFileExtensions}"
	fileExtension="{lib.txMediaUtils.responsiveImages.fileExtension}"
	loading="{lib.txMediaUtils.responsiveImages.settings.media.lazyLoading}"
	decoding="{lib.txMediaUtils.responsiveImages.settings.media.imageDecoding}"
/>
</html>

Testing

  • Single Method
ddev exec vendor/bin/phpunit -c vendor/madj2k/t3-media-utils/phpunit.xml \
vendor/madj2k/t3-media-utils/Tests/Unit/Whatever/Whatever.php \
--filter MethodName
ddev exec vendor/bin/phpunit -c vendor/madj2k/t3-media-utils/phpunit.functional.xml \
vendor/madj2k/t3-media-utils/Tests/Functional/Whatever/Whatever.php \
--filter MethodName
  • Single File
ddev exec vendor/bin/phpunit -c vendor/madj2k/t3-media-utils/phpunit.xml \
vendor/madj2k/t3-media-utils/Tests/Unit/Whatever/Whatever.php
ddev exec vendor/bin/phpunit -c vendor/madj2k/t3-media-utils/phpunit.functional.xml \
vendor/madj2k/t3-media-utils/Tests/Functional/Whatever/Whatever.php
  • All files
ddev exec vendor/bin/phpunit -c vendor/madj2k/t3-media-utils/phpunit.xml
ddev exec vendor/bin/phpunit -c vendor/madj2k/t3-media-utils/phpunit.functional.xml

Generate the documentation as HTML

Execute in the extension-root:

docker run --rm --pull always -v "$(pwd)":/project -it ghcr.io/typo3-documentation/render-guides:latest --config=Documentation

madj2k/t3-media-utils 适用场景与选型建议

madj2k/t3-media-utils 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.04k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 04 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 madj2k/t3-media-utils 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0
  • 更新时间: 2024-04-07