2017 © Pedro Peláez
 

library image-url-builder

Generate a full url from an image slug

image

mapado/image-url-builder

Generate a full url from an image slug

  • Wednesday, July 11, 2018
  • by jdeniau
  • Repository
  • 2 Watchers
  • 1 Stars
  • 16 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

image-url-builder

Generate a full url from an image slug, (*1)

Installation

composer require mapado/image-url-builder

Usage

use Mapado\ImageUrlBuilder\Builder;

$builder = new Builder();

$width = 800;
$height = 600;
$url = $builder->buildUrl('2018/01/foo.jpg', $width, $height);

// will output '//img.mapado.net/2018/01/foo_thumbs/800-600.jpg'

The first parameter of the buildUrl function accept an image "slug" or a full image url (starting with https://img.mapado.net/), (*2)

Force http(s) prefix

If you want to force http prefix, you can use the withHttpPrefix() or withHttpsPrefix() function before :, (*3)

$httpUrl = $builder
    ->withHttpPrefix()
        ->buildUrl($slug, $width, $height);
// will output `http://img.mapado.net/xxxx...`

$httpsUrl = $builder
    ->withHttpsPrefix()
        ->buildUrl($slug, $width, $height);
// will output `https://img.mapado.net/xxxx...`

With Twig

A Twig extension is available : Mapado\ImageUrlBuilder\Twig\UrlBuilderExtension, (*4)

You need to inject an instance of Mapado\ImageUrlBuilder\Builder to the constructor., (*5)

If you are using Symfony, the following configuration do work fine:, (*6)

services:
  Mapado\ImageUrlBuilder\Builder: ~

  Mapado\ImageUrlBuilder\Twig\UrlBuilderExtension:
    tags:
      - { name: twig.extension }

You can use the filter like this:, (*7)

<img src="{{ imageSlug|imageUrl(width, height) }}" />

The Versions

11/07 2018

dev-master

9999999-dev

Generate a full url from an image slug

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

11/07 2018

v1.2.1

1.2.1.0

Generate a full url from an image slug

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

11/07 2018

v1.2.0

1.2.0.0

Generate a full url from an image slug

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

11/07 2018

v1.1.0

1.1.0.0

Generate a full url from an image slug

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

11/07 2018

v1.0.0

1.0.0.0

Generate a full url from an image slug

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires