tomkyle/responsivepicture

此包的最新版本(1.2.8)没有可用的许可证信息。

PHP 对 HTML5 可响应图片元素的包装器

1.2.8 2014-08-28 09:22 UTC

This package is auto-updated.

Last update: 2024-09-11 18:01:16 UTC


README

# 可响应图片元素

Build Status Scrutinizer Code Quality Coverage Status

HTML5 图片元素的 PHP 包装器。参见

## 安装

此库除了测试用的 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 updateinstall 安装依赖,然后运行 phpunit