fileMethods for cropped images?

plugin
#1

Hey there,

I am trying to do some svg magic on my images. In short: I want to generate a svg representation of my images for some kind of preview (before the actual image is loaded).

I am using 'fileMethods' => […] for that. This works fine as long as I call my method on the original image like $myImage->svgPreview() but that’s not enough. Because I am cropping images, I need a preview for the cropped image, but: $image->crop(420, 195)->svgPreview() does not work, it seems like it’s not called at all.

So my question is: Is it possible to call a custom file method on a cropped/resized image?

#2

As far as I know this isnt possible, once its cropped (or resized or whatever) you cant chain further, since it a different file at that point, sitting in the media folder, rather then in the content where the source file was.

You would need your method to pick up the result of the crop, THEN do your preview.

#3

Once an image is cropped it is no longer a file object but a file version object, so file methods do not work anymore. Guess you could use a simple function to achieve that with a file version object.

#4

Okay, then I’ll try it another way. Thank’s or your help @texnixe and @jimbobrjames :slight_smile:

#5

@mauricehh, please upvote this issue if you want this functionality to be in core: https://github.com/getkirby/ideas/issues/242

Thanks :raised_hands:

1 Like