New File() not working inside thumb driver class

Hey there,
is there any way to access a file’s metadata when calling it with new Asset($pathToFile)?

Cheers,
S1SYPHOS

I’m not sure, but I think you need a Kirby\Cms\file object for that (as stated here: https://getkirby.com/docs/reference/objects/file)

I know - and for certain reasons I need a way around this limitation :wink:

But assets do not have metadata files, so the only information you could get from assets would be exif dats.

How would you want to store additional m assets metadata?

Well, I only have the path to the file (= $file), but doing this doesn’t seem to work:

$file = new Kirby\Cms\File([
  'root' => Kirby\Toolkit\F::dirname($file),
  'source' => $file,
  'filename' => Kirby\Toolkit\F::filename($file),
]);

It states that the file root is content, whereas it really should be content/home ?!

I’m not sure I understand what you are trying to do there. What is $file in your example above? The path to a file in the assets folder?

It’s the path to a file in content/home

Now I’m completely lost. Why don’t you fetch the file with page('home')->file('filename')?

Mhh, I honestly didn’t think about just calling page(), since what I’m trying to achieve takes place deep inside the thumb method and I thought it would not be available :confused: will try it!

But I would have to get the right page from the path, you know? Under controlled conditions, I know the page, but in my plugin, I need to find out, having only the path … :frowning:

It would be nice to expose / pass the file object being processed to the thumb() method though … I already added my Nolt feedback (or at least partly) about making it easier to create thumb drivers building on top of the Darkroom class.

It’s not possible to understand what you are trying to do with such little information and therefore my answer is going to be based on guessing…

To understand the thumbnail creation process, I suggest you have a look at the file::version component first (and read this). This is the first step in the process. In this component you have access to the $file object. All the logic e.g. calculations with meta data or whatever can be done here. The component then saves all data that is needed for the thumb creation in the .jobs folder. To add custom information, you simply add it to the $options array. The thumb method itself just consumes this .jobs json file and should not need to have access to the original $file object.

The file::version component is also the place where you can circumnavigate the isResizable() problem you mentioned somewhere else.

Alright, a little context might be in order:

I already identified what you are saying, and opened issue / PR, see here. My thumb driver (based on colorist) is already working, and although it’s still a work in progress (mainly because I’m missing sufficient documentation), it works just fine.

Right now, I’m trying to improve support for Flo Kosiol’s ‘Focus’ plugin inside the resize part of the class extending Darkroom. In order to comply with Kirby’s way a thumb driver is used, the only thing I got in there is the path to the image file being processed and the $options array.

Access to a file’s ‘focusX’ & ‘focusY’ values in a way that ppl don’t have to pass them explicitly to the thumb() method, but still can profit from the plugin (which might be an edge case, but for me it’s a brain teaser), I’ll have to access the x/y values of the file, meaning accessing its metadata (either directly or through Flo’s coordinates) method (which in turn takes the $file object as argument - surprise!).

So what I want - and asked precisely - is a way, through any means available, to access metadata of a file somewhere in the content folder, that I only know by path.

I tried this but it doesn’t work either ($file is the file’s path):

$path = Kirby\Toolkit\Str::replace($file, kirby()->root('content') . '/', '');
$path = Kirby\Toolkit\Str::replace($path, '/' . Kirby\Toolkit\F::filename($file), '');

$file = page($path)->file(Kirby\Toolkit\F::filename($file));

For /path/to/content/home/subpage, $path comes down to home/subpage, which is passed to page(), so this should work - but deep inside the thumb() method (see my explanation above) it doesn’t …