tomkyle / responsivepicture
此包的最新版本(1.2.8)没有可用的许可证信息。
PHP 对 HTML5 可响应图片元素的包装器
1.2.8
2014-08-28 09:22 UTC
Requires
- php: >=5.4.9
Requires (Dev)
- phpunit/phpunit: ~4.2
- satooshi/php-coveralls: dev-master
README
# 可响应图片元素
HTML5 图片元素的 PHP 包装器。参见
- Scott Jehl 的 Picturefill – 一个响应式图片 polyfill
- Picturefill 在 Github 上
## 安装
此库除了测试用的 satooshi/php-coveralls
没有其他依赖。可以通过命令行或 composer.json
文件安装
##### 命令行
composer require tomkyle/responsivepicture
##### composer.json "require": { "tomkyle/responsivepicture": "~1.2" }
## 入门
<?php
use \tomkyle\ResponsivePicture\MinWidthSource;
use \tomkyle\ResponsivePicture\ResponsivePicture;
use \tomkyle\ResponsivePicture\ResponsivePictureView;
$pic = new ResponsivePicture( '//placehold.it/300x300', "Sample image");
$pic->add( new MinWidthSource(1200, '//placehold.it/1200x1200, //placehold.it/2400x2400 2x'));
$pic->add( new MinWidthSource(800, '//placehold.it/800x800, //placehold.it/1600x1600 2x'));
$pic->add( new MinWidthSource(480, '//placehold.it/480x480, //placehold.it/960x960 2x'));
?>
## 创建输出 只需创建一个 ResponsivePictureView
实例并输出它,可选地传递你的 ResponsivePicture
对象。你可以从没有参数开始,稍后通过设置器方法或调用
<?php
// One-line call
echo new ResponsivePictureView( $pic );
// Use setter method
$foo = new ResponsivePictureView;
$foo->setPicture( $pic_view );
echo $foo;
// Or use with __invoke:
$bar = new ResponsivePictureView;
echo $bar( $pic1 );
echo $bar( $pic2 );
echo $bar( $pic3 );
?>
## 测试 前往包根目录,使用 composer update
或 install
安装依赖,然后运行 phpunit
。