@bnomei Did a great job with the srcset plugin for Kirby 3, but I cant seem to chain it after focus crop. I’m also using it inside the Builder plugin, which may or may not be contributing to it not working.
so its a Kirby\Cms\FileVersion as i expected. i will take a look why the hack above did not work. but since i need to setup the focus plugin to do proper testing i might not be able to fix it today.
Ok, so yes it seems like a FileVersion cannot be as simply chained as you would like to do it. It’s maybe something we could work on… but my own understanding is too limited at the moment to get onto it.
However, a quick idea I have: In your plugins, you could check whether you get a FileVersion object instead of a File object. If so, my train of thought is as follows:
FileVersion->original() should get you the original File object from the beginning of the chain
FileVersion->modifications() get you an array of the modifications that have been applied, basically the options for thumb generation from the previous step.
Take the modifications, merge them with your own modifications and apply them to the original File object.
That gives you a new FileVersion object, but this one now reflects modifications from all chain steps.
Return that one.
As said, I haven’t been able to test that thought process. But I’d be very curious to hear your thoughts or if this even works for you. Or maybe I am all wrong XD
@distantnative@jimbobrjames@flokosiol
i gave this some thought… as much as i like the idea of chaining it seems quiet complex for thumbs in concern to multiple plugins. but in our case this might not be needed. my srcset plugin already provides a hook for other resize calls. maybe you could think of focuscrop just like one single resize call.
so maybe using this config:
'resize' => function ($file, $width, $type) {
/*
* @jimbobrjames: custom filemethod return null or [w,h]
* you need to take care of calculations from 1600,550 to a w/h like 320,110
*/
if($c = $file->needsCrop($width)) {
return $file->focusCrop($c['w'], $c['h']);
}
return $file->resize($width);
}
Thanks for giving it thought. However if i understand you correctly, wouldnt that make it a “one shot wonder” - I could only ever do it for that specific size becuase it would be set in the config?
How hard would it be to meld the two plugins, so that your natively looks up the focus point and handles the crop around that point?