Generate imgix URLs from your antlers templates with the Statamic Imgix addon.
composer require withcandour/statamic-imgix
Then publish the publishables from the service provider:
php artisan vendor:publish --provider="WithCandour\StatamicImgix\ServiceProvider"
After publishing the config you will have a config/imgix.php
file. You will need to provide your imgix domain in here.
The addon will provide a set of Imgix tags for use in your antlers templates.
This addon will provide a set of imgix tags for generating imgix URL's and elements that use them. The minimum requirement for these tags is that you provide it with a path
parameter, this is the path or url for the asset source, it is recommended that you use the {{ path }}
variable returned inside of a pair of asset tags.
Tags will accept any of the Imgix manipulation parameters. Tags which generate a tag (such as the {{ imgix:image_tag }}
tag) will also accept all standard HTML attributes (i.e 'alt'), these will then get added to the element/tag produced.
Tag | Description |
---|---|
imgix | The base tag - this will simply generate an imgix URL |
imgix:image_url | An alias of {{ imgix }} |
imgix:image_srcset | Generates a srcset for use in an img tag |
imgix:image_tag | Generates an <img />; tag from your parameters |
imgix:responsive_image_tag | Generates an <img /> element with a srcset |
imgix:responsive_picture_tag | Generates an <picture /> element for displaying different images at different sizes |
For example:
return [
'srcset_resolutions' => [1, 4, 5],
];
For example:
{{
imgix:responsive_picture_tag
:path="path"
:alt="alt"
fit="crop"
crop="faces"
sizes="768: [1500x960]|560: [920x550]|200: [600x400]"
}}
This tag will produce a picture tag with sources so that:
- At 200-559px a 600x400 image will be shown
- At 560-767px a 920x550 image will be shown
- At 768px+ a 1500x960 image will be shown
This addon supports focalpoint cropping by using the {{ focus }}
variable, generated using the focal point selector in the CMS. In order to use focalpoint cropping in your templates, combine fit="crop"
, crop="focalpoint"
and focus="{focus}"
(or :focus="focus"
) in the tag.
For example:
{{ my_image_field }}
{{
imgix:responsive_image_tag
w="1920"
h="1080"
:path="path"
:alt="alt
fit="crop"
crop="focalpoint"
:focus="focus"
}}
{{ /my_image_field }}