maximal/php-avif-thumbnailer
最新稳定版本:v1.0.0
Composer 安装命令:
composer require maximal/php-avif-thumbnailer
包简介
PHP (over Imagine) helper for creating and caching AVIF thumbnails in real time
README 文档
README
AvifThumbnailer is a thumbnail helper which allows you to generate
and cache image thumbnails in your PHP application on the fly.
Installation
Install this library with Composer:
composer require "maximal/php-avif-thumbnailer"
or add
"maximal/php-avif-thumbnailer": "^1.0"
to the require section of your app’s composer.json file.
Checking the environment
You will need FFMPEG with AVIF (AV1) coder installed in your system.
For instance in Ubuntu/Debian it is included in ffmpeg package:
sudo apt install ffmpeg
Check the command:
ffmpeg -version
You should get an output with the version number. Every version after 4.3 should be fine.
If you have installed ffmpeg to a different command or path, configure
the static property AvifThumbnailer::$ffmpegCommand before using the helper
(see the example below).
More info about AVIF: https://avif.io/blog/
Generating thumbnails
Use this thumbnailer in your PHP application:
use Maximal\Thumbnailers\AvifThumbnailer; echo AvifThumbnailer::picture('/path/to/img/image.png', $width, $height);
More options (outbound instead of default inset; alt and class
attribute added):
use Maximal\Thumbnailers\AvifThumbnailer; echo AvifThumbnailer::picture( '/path/to/img/image.png', $width, $height, false, ['alt' => 'Alt attribute', 'class' => 'img-responsive'] );
Custom ffmpeg command:
use Maximal\Thumbnailers\AvifThumbnailer; AvifThumbnailer::$ffmpegCommand = '/usr/local/bin/ffmpeg'; echo AvifThumbnailer::picture('/path/to/img/image.jpg', $width, $height);
The helper’s picture() method uses modern <picture> HTML tag as follows:
<picture data-cache="hit|new|fail"> <source srcset="/assets/thumbnails/...image.png.avif" type="image/avif" /> <img src="/assets/thumbnails/...image.png" other-attributes="" /> </picture>
Here you have image/avif source for
browsers which support AVIF images
and traditional (PNG, JPEG, TIFF, GIF) image fallback.
Author
- Websites: https://maximals.ru and https://sijeko.ru
- StackOverflow story: http://stackoverflow.com/users/story/1021887
- Twitter: https://twitter.com/almaximal
- Telegram: https://t.me/maximal
统计信息
- 总下载量: 2.27k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-11-24