kiwa/source-collection
Composer 安装命令:
composer require kiwa/source-collection
包简介
The Kiwa Source Collection makes it easy to create HTML Audio, Picture and Video elements with multiple sources.
README 文档
README
Kiwa Source Collection
The Kiwa Source Collection makes it easy to create HTML audio, picture and video elements with multiple sources.
Installation
This library is made for the use with Composer. Add it to your project by running $ composer require kiwa/source-collection.
Usage
Creating a picture collection
To run the library in auto-mode, enable the auto search and tell the root folder, where all the images or video files are stored in:
<?php
use Kiwa\SourceCollection\Picture;
Picture::enableAutoSearchGenerally(
'path/to/dir'
);
After that, create a new Picture object with the file name you want to have to be printed later. This path may be relative.
<?php
$picture = new Picture('/build/images/my-image.jpg');
The library will search for files with the same name then and use them as additional sources. Print the object then:
echo $picture; // or $picture->getPicture()
Depending on the images there are available, the output could look like that:
<picture>
<source srcset="/build/images/my-image.webp" type="image/webp"/>
<source srcset="/build/images/my-image.jpg" type="image/jpeg"/>
<img src="/build/images/my-image.jpg"/>
</picture>
Creating a video collection
Creating a video element goes in the same way:
<?php
use Kiwa\SourceCollection\Video;
Video::enableAutoSearchGenerally(
'path/to/dir'
);
echo new Video('/some/path/test-file.mp4');
This will result in:
<video>
<source src="/some/path/test-file.mp4" type="video/mp4"/>
<source src="/some/path/test-file.mov" type="video/quicktime"/>
</video>
Creating an audio collection
Creating an audio element goes in the same way:
<?php
use Kiwa\SourceCollection\Audio;
Audio::enableAutoSearchGenerally(
'path/to/dir'
);
echo new Audio('/some/path/test-file.mp3');
This will result in:
<audio>
<source src="/some/path/test-file.mp3" type="audio/mpeg"/>
<source src="/some/path/test-file.ogg" type="audio/ogg"/>
</audio>
Options
Manual mode
You don't need to use the auto mode. Instead, you can add source files by your own:
<?php
use Kiwa\SourceCollection\Picture;
$picture = new Picture('/build/images/my-image.jpg');
$picture->addSourceFile('/build/images/my-image.webp');
Attributes
The constructor and the addSourceFile method have a second parameter, which can be used to add HTML parameters:
<?php
use Kiwa\SourceCollection\Picture;
echo new Picture(
'/build/images/my-image.jpg',
[
'alt' => 'This is a alt text',
'title' => 'This is a title text'
]
);
This will result in:
<picture>
<source srcset="/build/images/my-image.jpg" type="image/jpeg"/>
<img src="/build/images/my-image.jpg" alt="This is a alt text" title="This is a title text"/>
</picture>
Handling attributes globally
All attributes like the width and height can be stored and handled globally. It can be enabled like this:
<?php
use Kiwa\SourceCollection\AbstractSourceCollection;
AbstractSourceCollection::enableAttributeCache(
Path::getRootFolder() . DIRECTORY_SEPARATOR . 'attributes-cache'
);
Whenever a file is getting requested, the script will look for a file having the same name. For example
<?php
use Kiwa\SourceCollection\Picture;
echo new Picture('/build/images/my-image.jpg');
will cause the script to search for a file called build-images-my-image-jpg-attributes.php. The file itself should contain and return an array with attributes then, for example:
<?php
return [
'width' => 1024,
'height' => 938,
];
This is especially useful in combination with the Kiwa Console's AssetAttributeCacheCreateCommand, where all assets are getting scanned and their information exctracted automatically. It can even use image recognition to create the alt and title descriptions.
Help
If you have any questions, feel free to contact us under hello@bitandblack.com.
Further information about Bit&Black can be found under www.bitandblack.com.
kiwa/source-collection 适用场景与选型建议
kiwa/source-collection 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.59k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 10 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「source」 「html」 「video」 「picture」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kiwa/source-collection 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kiwa/source-collection 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kiwa/source-collection 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Texy converts plain text in easy to read Texy syntax into structurally valid (X)HTML. It supports adding of images, links, nested lists, tables and has full support for CSS. Texy supports hyphenation of long words (which reflects language rules), clickable emails and URL (emails are obfuscated again
Easy to use SDK with grabber for multiple platforms at once like YouTube, Dailymotion, Facebook and more.
A Laravel 5 Package for Using & Working With Emojis
A Laravel 5 Package Provider to Identify/detect a user's browser, device, operating system and Language
The yii2-videojs-widget is a Yii 2 wrapper for the [video.js](http://www.videojs.com/). A JavaScript and CSS library that makes it easier to work with and build on HTML5 video. This is also known as an HTML5 Video Player.
Thepeer official Laravel SDK
统计信息
- 总下载量: 6.59k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 1
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2020-10-29