Laravel-Backpack / FileManager

Admin interface for files & folders, using elFinder.
Other
90 stars 21 forks source link

How to retrieve thumbnail path in the view? #17

Closed kee0624 closed 2 years ago

kee0624 commented 2 years ago

Hi, I am using lazyload for loading the big image in the front end, and I saw the elfinder is auto-generating the thumbnail on the backend, may I know how do I retrieve the thumbnail path and show it to the front end?

promatik commented 2 years ago

Hi @kee0624! ElFinder generates thumbnails on demand, you can create a custom route for that, but I wound't recommend it, it's an heavy process, and if you website has hundreds of page views, it will bloat your server CPU with thumbnail renders.

I recommend you to create the thumbnail when you upload the image. You can find more on the docs; https://backpackforlaravel.com/docs/4.1/crud-fields#image-1

If you want to generate the thumbnail besides saving your image, after the main image save, you can use something like;

$size = 128;

$image->resize($size, null, function ($c) {$c->aspectRatio();});
Storage::disk($disk)->put("$path/$size/$filename", $image->stream($format, $quality));

For now I'll close this issue since it's not related with FileManager, but feel free to ask anything else if you need ✌