This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.

Generate a full url from an image slug

v2.1.0 2021-02-25 11:28 UTC

This package is auto-updated.

Last update: 2021-08-25 13:02:55 UTC


Generate a full url from an image slug


composer require mapado/image-url-builder


use Mapado\ImageUrlBuilder\Builder;

$builder = new Builder();

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

// will output '//'

The first parameter of the buildUrl function accept an image "slug" or a full image url (starting with

Force http(s) prefix

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

$httpUrl = $builder
        ->buildUrl($slug, $width, $height);
// will output ``

$httpsUrl = $builder
        ->buildUrl($slug, $width, $height);
// will output ``

With Twig

A Twig extension is available : Mapado\ImageUrlBuilder\Twig\UrlBuilderExtension

You can use the filter like this:

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