Hide certain files in the panel and when loading $page->files();

I am working on on integrating the Image Optim API (https://imageoptim.com/api) into my Kirby site. This service compresses images for you and returns the new compressed asset.

Thinking the workflow would be that I hook into Kirby and listen for file upload. When a file (image) is uploaded I would send it off, download the new asset, and save it to the page’s files. It would probably be a good idea to keep the original file on hand, but I wouldn’t want to show the original file in the Panel file listing or when loading a page’s files.

I was thinking I could build a custom files method and extend to filter them out, but it says you can’t override the built-in methods.

The only option I have come up with would be to add a period at the beginning of the original file name to convert it to a hidden file. Example after uploading hello.jpg it would get renamed to .hello.jpg and a compressed hello.jpg would be added.

Any thoughts?

My idea was to overwrite the thumb component and create the images once they are loaded and cache them. That way you could just throw in a Plugin and once ImageOptim decides what their pricing looks like you can just remove the plugin if you want or keep it.

This is a good idea. Thanks, I’m surprised this didn’t show up when I was looking through the forums. I’ll build it into the thumbs call.

ImageOptimAPI only caches an image for 3 hours, so beyond that it’s generating the image on the fly. In my tests this is still a bit slow. I’m going to build it to make the call and retrieve the compressed asset then save it locally. That way an API call is only needed once after upload.