croxton / imgixer

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

Focal point and Imgix #8

Closed terryupton closed 1 year ago

terryupton commented 1 year ago

Hey @croxton

Sorry, I have come across another issue/question and that is regarding focal-points. I have set a focal point on an image to test this, but it has not automatically been passed to imgix. I was hoping this would be automatically done via the plugin. If not would this be possible? Rather than having to manually set this and pass it to imgix.

Thanks Terry

croxton commented 1 year ago

It won't automatically pass the focal point (because it doesn't make any assumptions), but you can pass that information via the "fp-x":image.focalPoint.x and "fp-y":image.focalPoint.y parameters, which will be used when fit:"crop" and crop:"focalpoint". You can also use the fp-z param to set a zoom value.

I guess I could consider adding the "fp-x" and "fp-y" params automatically when both fit:"crop" and crop:"focalpoint". Generally I've tried not to make assumptions given how flexible the idea of 'focus points' is in Imgix (with entropy, faces etc). But I can see how it would be convenient so long as it doesn't impact on anything else.

terryupton commented 1 year ago

Thanks @croxton - appreciate not wanting to make assumptions, but I would expect if focal point has been set in the back-end most use cases would want to use this. I see there were some references to focal-point in some of the files, so assuming you have set this for servd and imagekit? Or have I got that wrong?

It would be a nice addition to imgix if mode is set to crop etc. Would avoid another set f manual params to be setup, and potentially forgotten/overlooked. 👍🏻

Happy to talk it over further if you want. 😁

croxton commented 1 year ago

I've added that!

To try it out set this as your semver if you haven't already:

"croxton/imgixer": "dev-feature/imagekit as 2.0.0-beta.1"

Run this to update to the latest commit on that branch:

composer clear-cache && composer update

When you use like this the fp-x and fp-y params will be populated automatically from the image:

<img src="{{ image | imgix({ w:300, h:300, fit:'crop', crop:'focalpoint' }) }}" alt="">
terryupton commented 1 year ago

Thanks for adding this @croxton - tested and works when setting it inside the imgix filter. It would be also amazing if this could be set on the defatParams inside the imgixer.php file like so:

$default_params = array(
  'provider'      => 'imgix',
  'endpoint'      => getenv('IMGIX_URL'),
  'privateKey'    => getenv('IMGIX_KEY'),
  'signed'        => true,
  'defaultParams' => array(
    'auto' => 'compress,format,enhance',
    'fit'  => 'crop',
    'crop' => 'focalpoint',
    'ar'   => '8:5',
    'step' => '100',
    'q'    => '80'
  ));
croxton commented 1 year ago

That should already work.. did you try it?

terryupton commented 1 year ago

That should already work.. did you try it?

I did try it and it didn't seem to work. I had set a from and to. I'll give it another check. But it worked in the function but not in the settings.

terryupton commented 1 year ago

Hey @croxton Happy New Year! Hope you had a good Christmas break.

Just to let you know I have tested this again and I can confirm unfortunately, it does not work when it is only set in the imgixer.php file.

Do you think you could have a look and see if we can achieve this? Thanks.

croxton commented 1 year ago

Happy New Year! I'll take a look this week and figure out why that's not working.

croxton commented 1 year ago

I found the problem and fixed it - please give it a go (composer update).

terryupton commented 1 year ago

Hey Mark. I can confirm this is working now. Perfect 🎉. Thank you.