borodin-vasiliy/php-stories
Composer 安装命令:
composer require borodin-vasiliy/php-stories
包简介
PHP-Library for create stories using images, text and animation. Use GD-Library
关键字:
README 文档
README
PHP-Library for create video-stories (MP4) using images, text and animations for them. Dependence of the GD-library. This library create stories frame by frame and after that create video using ffmpeg. ffmpeg should be installed on your server!
Quick Start
Install the library using composer:
composer require borodin-vasiliy/php-stories
Examples
On examples dir you can found 2 samples how to use this library, below i will show how to create stories.
Create object of the library
<?php use BorodinVasiliy\Stories; $stories = new Stories([ "width" => $stories_width, "height" => $stories_height, "duration" => $stories_duration ]); ?>
How you can see, args of library is array with some params. Which params you can use:
- "width" - width in px of stories layout
- "height" - height in px of stories layout
- "duration" - duration of stories in seconds
- "fps" - frame per second - how many frames will be created for each second of the video
All params are not required. If not set than, library will use default values 720x1280px, 5 seconds, 30 fps.
Now your future stories is ready for adding some elements to the video. In current moment you can add image, text, rectangle, ellipse with animation for them.
Add objects to stories
Library has methods for adding each type of objects. Every time args of method - array of params. All object-types has general params:
- "top" - position of image from top
- "left" - position of image from left
- "opacity" - like css opacity - opacity of element [0 .. 1]
- "rotate" - rotation of element [0 .. 359]
- "z-index" - like css z-index - at first on layer will be added elements with less z-index
- "start" - second, when element will be added to video
- "end" - second, when element should be removed from video
And objects has additional params for this type. Lets learn, how to add each type of object to video and which params we can use.
Add image to stories
<?php $stories->addImage([ "path" => __DIR__."image/cat.jpg", /*params*/ ]); ?>
Additional params for images:
- "path" - required - required param with path and filename of image, ex. DIR."image/cat.jpg"
- "scale" - 1 default - scale of element, we dont have width and height params, just scale
Add text to stories
<?php $stories->addText([ "text" => "Hello world!", "path" => __DIR__."/fonts/helvetica.ttf", "size" => 130, /*other params*/ ]); ?>
Additional params for text:
- "text" - required - Text, that you wanna add
- "path" - required - path to font .ttf file
- "size" - required - like css font-size
- "color" - like css color, ex "#ffffff"
- "width" - not required, if you use this param, text will be automatically splited to lines with setted width
- "align" - like css align [left, center, right]
- "shadow" - array of params, if you set them, this text will have shadow:
- "color" - color of this shadow
- "top" - offset from main text
- "left" - offset from main text
Add rectangle to stories
<?php $stories->addRectangle([ "width" => 100, "height" => 100, /*other params*/ ]); ?>
Additional params for rectangle:
- width - required - width of this rectangle
- height - required - height of this rectangle
- color - like css color of this rectangle
Add ellipse to stories
<?php $stories->addEllipse([ "width" => 100, "height" => 100, /*other params*/ ]); ?>
Additional params for ellipse:
- width - required - width of this ellipse
- height - required - height of this ellipse
- color - like css color of this ellipse
Animation
Each object on video can be animated. Animation is change some param from start-value to animated value. Count of animations not limited. Each animation has own duration. Duration can be less then life-time of this element. When animation is done, animated param will be set like final point.
All types of objects has general params for animation:
- "start" - Second, when this animation should start
- "duration" - duration of animation (You can set or "duration", or "end" param)
- "end" - Second, when this animation should be finished
- "top" - To which position move this object
- "left" - To which position move this object
- "opacity" - To which opacity move this object
- "rotate" - Degree to rotate this element
And additional (just for this type):
- "scale" - for images
- "width" - for rectangle and ellipse
- "height" - for rectangle and ellipse
This library use Fluent Interface. That mean, you add element, after that can add animation for this element:
<?php $stories->addImage([ /* image params */ ])->addAnimation([ /* params for animation */ ]); ?>
Generate stories
When you add all elements to your stories and set animation, you ready for generate animation and result video.
<?php $file_hash = $stories->generate(__DIR__."/tmp"); ?>
As arg of function - path to temporary dir, where will be saved frames and result video-file (MP4). As result of method generate() you will receive filename of result video in temporary dir. Generated frames will be automatically removed.
Sample of stories
borodin-vasiliy/php-stories 适用场景与选型建议
borodin-vasiliy/php-stories 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 278 次下载、GitHub Stars 达 36, 最近一次更新时间为 2018 年 12 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「facebook」 「video」 「instagram」 「vkontakte」 「social network」 「animation」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 borodin-vasiliy/php-stories 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 borodin-vasiliy/php-stories 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 borodin-vasiliy/php-stories 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Handles basic OAuth/OAuth2 authentication along with classes for common services
Craft CMS plugin to receive Instagram feed data as variable in templates.
Easy to use SDK with grabber for multiple platforms at once like YouTube, Dailymotion, Facebook and more.
Simple Sharing generates social media share links within CP entry pages, allowing you to quickly & easily share entries.
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.
Display a video using native HTML5 video
统计信息
- 总下载量: 278
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 36
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-12-16