PHP code example of tomkyle / responsivepicture

1. Go to this page and download the library: Download tomkyle/responsivepicture library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tomkyle / responsivepicture example snippets


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

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