croxton / imgixer

Generate Imgix URLs in Craft 3
MIT License
11 stars 4 forks source link

Web proxy usage with Imgix #2

Closed steverowling closed 3 years ago

steverowling commented 3 years ago

How do I set up the config for this plugin to use Imgix with web proxy sources?

croxton commented 3 years ago

With Imgix used as a proxy you need to provide the absolute URL to the image you want to proxy. You can do that at the template level (if you need to proxy multiple domains), or create a source for each proxied domain in your config and pass the proxy domain to the subfolder.

So for example you can have a config like this:

return [
   'my-proxy' => array(
            'domain'   => 'my-proxy-source.imgix.net',
            'subfolder' => 'https://www.my-proxied-website.com/',
            'key'   => 'XXXXXXXXXXXX',
            'defaultParams' => array(
                'auto' => 'compress,format',
                'fit' => 'crop',
                'q' => '80'
            )
        ),
   )
];

And use like this in templates:

{{'uploads/my-image.jpg' | imgix({ source:'my-proxy', ar:'3:2', w:1200, signed: true }) }}

Or a config like this:

return [
   'my-proxy' => array(
            'domain'   => 'my-proxy-source.imgix.net',
            'key'   => 'XXXXXXXXXXXX',
            'defaultParams' => array(
                'auto' => 'compress,format',
                'fit' => 'crop',
                'q' => '80'
            )
        ),
   )
];

And use like this in templates:

{{'https://www.my-proxied-website.com/uploads/my-image.jpg' | imgix({ source:'my-proxy', ar:'3:2', w:1200, signed: true }) }}
{{'https://www.another-proxied-website.com/uploads/another-image.jpg' | imgix({ source:'my-proxy', ar:'3:2', w:1200, signed: true }) }}
steverowling commented 3 years ago

Ah, by using the subfolder setting! I should have realised. Thanks!