spacecatninja / craft-imager-x-imagekit-transformer

ImageKit transformer for Imager X
MIT License
0 stars 2 forks source link

imageKit drop-in replacement for Imgix - but cannot render images using `addPath` #1

Closed terryupton closed 1 year ago

terryupton commented 1 year ago

I am investigating a migration from imgix to imagekit and I was hoping it would be a drop-in replacement. I have set everything up that I believe is correct and here is my imager-x-imagekit-transformer.php config.

<?php
return [
    'publicKey' => 'REDACTED',
    'privateKey' => 'REDACTED',
    'profiles' => [
        'default' => [
            'urlEndpoint' => 'REDACTED',
            'isWebProxy' => false,
            'useCloudSourcePath' => true,
            'addPath'                    => [
                'images'   => 'images',
                'projects' => 'projects',
                'staff'    => 'staff',
            ],
        ]
    ],
    'defaultProfile' => 'default'

];

The Imgix config was as follows for the sources:

 'addPath'                    => [
          'images'   => 'images',
          'projects' => 'projects',
          'staff'    => 'staff',
        ],

However, I am unable to render any images at all with this setup. Getting 404 errors for the images. The imagekKit is a web folder and is the same as I am using on imgix.

I had assumed the addPath setting in imagekit would operate the same as imgix, so it would more-or-less be a drop-in replacement.

Can you offer any advice on what I might need to tweak settings and if it can be done with as little code changes as possible.

Thanks

terryupton commented 1 year ago

My base url is set to https://www.swh.co.uk/uploads inside ImageKit.

Screenshot 2023-07-14 at 16 08 14

Inside 'images' and 'projects' I have sub folders that are created in craft.

Screenshot 2023-07-14 at 16 08 31
terryupton commented 1 year ago

Ah-ha. I think I have figured it out.

Inside imageKit, you need to create a External storage for each of the Craft asset volumes. Then you need to attach these to the URL endpoint. Then you add the 'addPath' setting. This seems to have now resolved the issue.

aelvan commented 1 year ago

This was a bug. You should be able to add an external storage that points to /uploads, and then use addPath to map the volumes to subfolders, as with Imgix.

The solution you encountered, is a Imagekit feature that Imgix doesn't have. You can add as many external storages to an url endpoint, and have Imagekit pull from all of them directly (without using addPath). The caveat is that you could get name collisions across your storages, hence the option to prioritize external storages inside an url endpoint.