tomkyle/responsivepicture

There is no license information available for the latest version (1.2.8) of this package.

A PHP wrapper for responsive HTML5 picture elements

1.2.8 2014-08-28 09:22 UTC

This package is auto-updated.

Last update: 2024-11-11 18:15:50 UTC


README

#Responsive Picture Elements

Build Status Scrutinizer Code Quality Coverage Status

A PHP wrapper for HTML5 picture element. See:

##Installation

This library has no dependencies except from satooshi/php-coveralls for testing. Install from command line or composer.json file:

#####Command line

composer require tomkyle/responsivepicture

#####composer.json "require": { "tomkyle/responsivepicture": "~1.2" }

##Getting started

<?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'));
?>

##Create output Just create a ResponsivePictureView instance and echo it, optionally passing your ResponsivePicture object. You may start with no parameters and later set the ResponsivePicture, either by setter method or invoking:

<?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 );    
?>

##Testing Go to package root, install dependencies with composer update or install, run phpunit.