2017 © Pedro Peláez
 

library responsible-images

A PHP library for generating responsive image URLs and HTML tags

image

stevenberg/responsible-images

A PHP library for generating responsive image URLs and HTML tags

  • Tuesday, April 24, 2018
  • by stevenberg
  • Repository
  • 1 Watchers
  • 0 Stars
  • 297 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 19 Versions
  • 22 % Grown

The README.md

Responsible Images

A PHP for generating responsive image URLs and HTML tags., (*1)

Installation

Install with composer:, (*2)

composer require stevenberg/responsible-images

Use Cloudinary images with stevenberg/responsible-images-cloudinary:, (*3)

composer require stevenberg/responsible-images-cloudinary

Example

Here's an example of using the library in a Laravel project:, (*4)

// app/Providers/ResponsibleImagesServiceProvider.php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use StevenBerg\ResponsibleImages\Urls\Cloudinary;
use StevenBerg\ResponsibleImages\Urls\Maker;

class ResponsibleImagesServiceProvider extends ServiceProvider
{
    public function boot()
    {
        Maker::registerDefaultMaker(new Cloudinary);
    }
}
// app/Image.php

namespace App;

use Illuminate\Database\Eloquent\Model;
use StevenBerg\ResponsibleImages\Image as ResponsibleImage;
use StevenBerg\ResponsibleImages\Urls\Cloudinary;
use StevenBerg\ResponsibleImages\Values\Gravity;
use StevenBerg\ResponsibleImages\Values\Shape;

class Image extends Model
{
    protected $fillable = ['gravity', 'name', 'shape'];

    public function getGravityAttribute($value)
    {
        return Gravity::from($value);
    }

    public function setGravityAttribute(Gravity $value)
    {
        $this->attributes['gravity'] = $value->value;
    }

    public function getShapeAttribute($value)
    {
        return new Shape($value);
    }

    public function setShapeAttribute(Shape $value)
    {
        $this->attributes['shape'] = $value->value;
    }

    public function getResponsiveImageAttribute()
    {
        return ResponsibleImage::fromShape(
            $this->shape,
            $this->name,
            ['gravity' => $this->gravity]
        );
    }
}
// app/helpers.php

use App\Image;
use StevenBerg\ResponsibleImages\SizeRange;

function responsive_image_tag(
    Image $image,
    int $min,
    int $max,
    int $step,
    array $attributes)
{
    $range = SizeRange::from($min, $max, $step);

    echo $image->responsive_image->tag($range, $range->first(), $attributes);
}

The Versions

24/04 2018

2.0.1

2.0.1.0

A PHP library for generating responsive image URLs and HTML tags

  Sources   Download

MIT

The Requires

 

The Development Requires

by Steven Berg

responsive images

28/02 2018

2.0.0

2.0.0.0

A PHP library for generating responsive image URLs and HTML tags

  Sources   Download

MIT

The Requires

 

The Development Requires

by Steven Berg

responsive images

22/02 2018

1.1.0

1.1.0.0

A PHP library for generating responsive image URLs and HTML tags

  Sources   Download

MIT

The Requires

 

The Development Requires

by Steven Berg

responsive images

20/02 2018

1.0.2

1.0.2.0

A PHP library for generating responsive image URLs and HTML tags

  Sources   Download

MIT

The Requires

 

The Development Requires

by Steven Berg

responsive images

20/02 2018

dev-master

9999999-dev

A PHP library for generating responsive image URLs and HTML tags

  Sources   Download

MIT

The Requires

 

The Development Requires

by Steven Berg

responsive images

20/02 2018

1.0.1

1.0.1.0

A PHP library for generating responsive image URLs and HTML tags

  Sources   Download

MIT

The Requires

 

The Development Requires

by Steven Berg

responsive images

26/04 2017

1.0.0

1.0.0.0

A PHP library for generating responsive image URLs and HTML tags

  Sources   Download

MIT

The Requires

 

The Development Requires

by Steven Berg

responsive images

31/03 2017

0.5.3

0.5.3.0

A PHP library for generating responsive image URLs and HTML tags

  Sources   Download

MIT

The Requires

 

The Development Requires

by Steven Berg

responsive images

31/03 2017

0.5.2

0.5.2.0

A PHP library for generating responsive image URLs and HTML tags

  Sources   Download

MIT

The Requires

 

The Development Requires

by Steven Berg

responsive images

31/03 2017

0.5.1

0.5.1.0

A PHP library for generating responsive image URLs and HTML tags

  Sources   Download

MIT

The Requires

 

The Development Requires

by Steven Berg

responsive images

31/03 2017

0.5.0

0.5.0.0

A PHP for generating responsive image URLs and HTML tags

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

by Steven Berg

responsive images

30/03 2017

0.4.1

0.4.1.0

A PHP for generating responsive image URLs and HTML tags

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

by Steven Berg

responsive images

30/03 2017

0.4.0

0.4.0.0

A PHP for generating responsive image URLs and HTML tags

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

by Steven Berg

responsive images

23/03 2017

0.3.1

0.3.1.0

A PHP for generating responsive image URLs and HTML tags

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

by Steven Berg

responsive images

23/03 2017

0.3.0

0.3.0.0

A PHP for generating responsive image URLs and HTML tags

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

by Steven Berg

responsive images

17/03 2017

0.2.1

0.2.1.0

A PHP for generating responsive image URLs and HTML tags

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

by Steven Berg

responsive images

17/03 2017

0.2.0

0.2.0.0

A PHP for generating responsive image URLs and HTML tags

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

by Steven Berg

responsive images

16/03 2017

0.1.1

0.1.1.0

A PHP for generating responsive image URLs and HTML tags

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

by Steven Berg

responsive images

16/03 2017

0.1.0

0.1.0.0

A PHP for generating responsive image URLs and HTML tags

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

by Steven Berg

responsive images