The image factory can be called using the image_factory() helper function from within PHP (.php and .blade.php) and Twig (.twig) files. When initializing an instance, the width and height of the resized image must be provided (in pixels).

The image factory outputs a signed URL to the resized image with an embedded validation token. This prevents being able to generate an infinite number of uniquely configured URLs that would drain the resources on the server.



image_factory(600, 800);
// outputs:

image_factory(600, 800)->path('/images/example.jpg');
// outputs:

image_factory(600, 800)->path('/images/example.jpg')->retina();
// outputs:



{{ image_factory(600, 800) }}
{# outputs: #}

{{ image_factory(600, 800).path('/images/example.jpg') }}
{# outputs: #}

{{ image_factory(600, 800).path('/images/example.jpg').retina() }}
{# outputs: #}

If using the Aero component system (Vue.js template within a .twig file), the image URL can be built by merging the image factory prefix with the JavaScript variable:



<div v-if="image">
        <source :srcset="'{{ image_factory(600, 600) }}/' + image.file + '.webp 1x,{{ image_factory(600, 800).retina() }}/' + image.file + '.webp 2x'"
        <img :src="'{{ image_factory(600, 600) }}/' + image.file"
             :srcset="'{{ image_factory(600, 600).retina() }}/' + image.file + ' 2x'"

Articles in this section

Was this article helpful?
0 out of 0 found this helpful